给字符串中的每个单词加上双引号,如何实现呢?
有答案:
Console.WriteLine( "Enter a string: ");
string myString = Console.ReadLine();
string[] myWords = myString.Split( ' ');
Console.WriteLine( "Adding double quotes areound words: ");
foreach (string myWord in myWords)
{
Console.Write( "\ "{0}\ " ", myWord);
}
但是如果string中有连续2个以上的空格,答案看起来就好象是不对了,双引号太多了,怎么能解决呢?谢谢!
新手,谢谢帮助!
------解决方案--------------------foreach (string myWord in myWords)
{
if(myWord.Length != 0)
Console.Write( "\ "{0}\ " ", myWord);
}