語法檢查在我的項目中的一部分。 我有一個段落,我想將每個句子的所有首字母改爲大寫。 句子中的所有其他字母必須小寫。如何將每個句子的第一個字母轉換爲大寫字母,將所有其他字母轉換爲小寫字母?
"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
當然,你不能解決專有名稱問題,它應該有主要上限,或者縮寫問題,這應該是全部上限。 –