假設我有一個字符串,如下所示:如何在首次換行後取出所有單詞?
User.
This is first line after line break.
This is second line after line break.
//Blank Line
This is fourth line.
我如何可以獲取的第一行突破之後出現的所有單詞。 因此,在上述情況下,我想檢索:
該「用戶」的下一行後發生This is first line after line break.
This is second line after line break.
//Blank Line
This is fourth line.
即任何東西。
所以基本上字符串將包含以下內容:
User\r\n\r\nThis is first line after line break. //and so on
我目前做如下:
// consider demoString is the string variable which holds the entire string mentioned above
commentStringToSearch = "User";
commentStringIndex = demoString.IndexOf(commentStringToSearch, StringComparison.OrdinalIgnoreCase);
if (commentStringIndex != -1)
{
commentValue = demoString.Substring(commentStringIndex + commentStringToSearch.Length);
}
但這段代碼的問題是,它會後取什麼單詞'User'包括第一行的空格。
我的預期輸出是讓他們從第二行到最後一行中的任何一個。
按照上面的例子我的預期成果是得到如下:
This is first line after line break.
This is second line after line break.
//Blank Line
This is fourth line.
(忽略一切從第一行,並接受第二行開始的任何東西)
在此先感謝。
拆分。現在你有所有的線路。根據需要繼續。 – Will
獲得「用戶」索引後,只需找到索引後的第一個換行符的索引即可。 – juharr
@stuartd你應該把它作爲答案。 – Fildor