所以乾脆: 所有我想要的是:如何計算兩個引號之間的文本?
輸入:嘿 「有我在想你」 「再一次」
輸出:2
Inpu噸:嘿「我在想你」「再一次」「開玩笑」
輸出:3
計數的空間從來沒有與我工作是因爲:有引號之間我測試,但從未工作過,因爲上面的原因
代碼文本空間...
static int CountWords(string text)
{
int wordCount = 0, index = 0;
while (index < text.Length)
{
while (index < text.Length && !char.IsWhiteSpace(text[index]))
index++;
wordCount++;
while (index < text.Length && char.IsWhiteSpace(text[index]))
index++;
}
return wordCount;
}
你打敗了我。這是一個[小提琴](https://dotnetfiddle.net/Y2zJTM)它的行動 – maccettura