本文介绍了Capitalise首字母串(安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法转换为资本的第一个字母的字符串:

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();

这篇关于Capitalise首字母串(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 22:15