可能重複:
How to split string preserving whole words?C# - 如何分割字符串
我有以下字符串:
string s = "The Electors shall meet in their respective states to vote by ballot for President and Vice-President.";
我要採取的第一個60個字符,將它們分成兩個單獨的字符串,每個字符串不超過30個字符每個字符串必須以整個單詞開頭(不包含部分單詞,也不包含空格)。所以這是期望的結果:
string s1 = "The Electors shall meet in"; // 26 characters
string s2 = "their respective states to vot"; // 30 characters
謝謝。
這個問題已經在這裏回答了http://stackoverflow.com/questions/4398270/how-to-split-string-preserving-whole-words。 –