我无法转换为资本的第一个字母的字符串:
I'm having trouble converting the first letter to Capital in a String:
rackingSystem.toLowerCase(); // has capitals in every word, so first convert all to lower case
StringBuilder rackingSystemSb = new StringBuilder();
rackingSystemSb.append(rackingSystem);
rackingSystemSb.setCharAt(0, Character.toUpperCase(rackingSystemSb.charAt(0)));
rackingSystem = rackingSystemSb.toString();
似乎这不是工作..
This doesn't seem to work..
有什么建议?
试着做:
rackingSystem = rackingSystem.toLowerCase();
相反的:
rackingSystem.toLowerCase();
字符串是不可变的,你必须重新分配与toLowerCase的结果()
。
不过更简单,(只要你的字符串大于长度2大):
Easier though, (as long as your String is larger than length 2):
rackingSystem = rackingSystem.substring(0,1).toUpperCase() + rackingSystem.substring(1).toLowerCase();