我有一个String test="The Mountain view"
,我需要字符串中空格后的所有字符都需要大写,例如上面的文本'M '
空格后为大写,String 中空格后的每个字符都需要反射(reflect)条件。
我需要一个正则表达式或条件来检查空格后的所有字符是否为大写,否则我需要将空格后的字符串更改为大写字符(如果它是小写)。
如果有人知道意味着帮助我。
谢谢。
最佳答案
不需要正则表达式。试试这个例子,也许有帮助:
public class Capitalize {
public static String capitalize(String s) {
if (s.length() == 0) return s;
return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
}
public static void main(String[] args) {
while (!StdIn.isEmpty()) {
String line = StdIn.readLine();
String[] words = line.split("\\s");
for (String s : words) {
StdOut.print(capitalize(s) + " ");
}
StdOut.println();
}
}
}
关于java - android中字符串的 Camel 大小写验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6786673/