public String changeFirstCharFromLowToUp(String oldWord)
{
String[] b = new String[oldWord.length()];
for(int i = 0; i[list=1] [h] + [allo] ?!?
Dann könnte ich mir eine for-Schleife sparen.
Gruß
public String lower2Upper(String message)
{
char newChar = message.charAt(0);
newChar = Character.toUpperCase(newChar);
message = message.replaceFirst(String.valueOf(message.charAt(0)),
String.valueOf(newChar));
return message;
}
public class RegExExample {
static String toUpperCase(final Pattern pattern, final String s) {
StringBuffer sb = new StringBuffer(s.length());
Matcher m = pattern.matcher(s);
while(m.find()) {
m.appendReplacement(sb, m.group().toUpperCase());
}
m.appendTail(sb);
return sb.toString();
}
// Erster Buchstabe eines jeden Wortes
static final Pattern PATTERN1 = Pattern.compile("(\\b.{1})");
static String toUpperCase1(String s) {
return toUpperCase(PATTERN1, s);
}
// Erster Buchstabe eines Wortes in einer Zeile
static final Pattern PATTERN2 = Pattern.compile("^\\s*(\\b.{1})", Pattern.MULTILINE);
static String toUpperCase2(String s) {
return toUpperCase(PATTERN2, s);
}
public static void main(String[] args) {
String s = "dies ist ein test\n mit mehreren\n zeilen";
System.out.println(toUpperCase1(s));
System.out.println();
System.out.println(toUpperCase2(s));
}
}
String string = Character.toUpperCase(string.charAt(0)) + string.substring(1, string.length());