语法检查在我的项目中的一部分。 我有一个段落,我想将每个句子的所有首字母改为大写。 句子中的所有其他字母必须小写。如何将每个句子的第一个字母转换为大写字母,将所有其他字母转换为小写字母?
"lijo was very intelligent.but his Character was not Good.He Played FootBall .
he is veryClever,and wise."
output
"Lijo was very intelligent.But his character was not good.He played football .
He is veryclever,and wise."
我也做了上述这样的:
public static void main(String[] args) {
String org= "lijo was very 'intelligent . but his Character was not Good.He Played FootBall .he is veryClever,and wise.";
String [] temp=org.split("\\.");
int len=temp.length;
String ne = ".";
for(int i=0;i<len;i++)
{
temp[i]=temp[i].toUpperCase();
temp[i]=(temp[i].substring(0, 1)).toUpperCase()+(temp[i].substring(1, temp[i].length())).toLowerCase();
System.out.println(temp[i]);
}
}
有没有更简单的方法来做到这一点?
上面的代码是否工作? –
是的,它给出了输出,但我正在寻找一个简单的想法。 – Lijo
当然,你不能解决专有名称问题,它应该有主要上限,或者缩写问题,这应该是全部上限。 –