我需要将字符串值转换为大写(每个单词的首字母变为大写)。 这可以通过使用 ucwords() 方法在 php 中完成。
例如:
String myString = “HI GUYS”;
myString = myString. toLowerCase().replaceAll(“Regex”, “Some Charactor”)
感谢 hi5
最佳答案
使用regex
,会很困难。尝试以下简单代码:
String str="hello world";
String[] words=str.split(" ");
for (String word : words) {
char upCase=Character.toUpperCase(word.charAt(0));
System.out.print(new StringBuilder(word.substring(1)).insert(0, upCase));
}
输出:
Hello World
关于java - 像ucwords一样使用正则表达式制作首字母大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19828111/