首先, d考慮推送獲取原始消息而不是訴諸於這些措施,因爲結果不會很完美。
您可以使用正則表達式[\.\!\?]\b
,它被定義爲標點符號,後面跟着單詞的開頭。
示例代碼:
static void Main(string[] args)
{
Console.WriteLine(RestoreNewlines("This is the end of the first paragraph.And this is the start of the second. This is the start of the third."));
Console.WriteLine(RestoreNewlines("Example of a case.txt where it fails."));
}
private static readonly Regex PunctuationWithoutFollowingWhitespaceRegex = new Regex(@"[\.\!\?]\b");
static string RestoreNewlines(string input)
{
return PunctuationWithoutFollowingWhitespaceRegex.Replace(input, match => match.Value + Environment.NewLine);
}
輸出:
This is the end of the first paragraph.
And this is the start of the second. This is the start of the third.
Example of a case.
txt where it fails.
來源
2015-09-04 19:49:32
Bas
PS,我會恢復的郵件,如果他們被查閱:他們被彈出通過他們使用的工具的服務器。 –