"jay" <> schrieb im Newsbeitrag
news: om...
> I cannot seem to figure out what should be a simple regex:
> given a String x, how do I make the first letter of x capitalized?
public static String up1(String s) {
return (s.length()>0)? Character.toUpperCase(s.charAt(0))+s.substring(1) :
s;
}
You don't need a regular expression for this task. They are used for
matching/parsing issues. However, e.g. "[A-Z]" matches uppercase letters
while [a-z] matches lowercase letters.
E.g.
....
Pattern p = Pattern.compile("[a-z]*");
Matcher m = p.matcher("lUUU");
....
m.matches() --> true
Marc
|