使用string.Split
和Char
数组,您可以在该数组中指定任意数量的字符。只需添加更多的字符,这将导致分裂:
char[] splitChars = new char[] { '.', '!', '?', ',' };
var ArraySourceTexts = textbox.Text.Split(splitChars, StringSplitOptions.RemoveEmptyEntries);
输入:
this is an example. Please check, and let me know your thoughts!
输出:
[0] this is an example
[1] Please check
[2] and let me know your thoughts
方法2:如果要拆分字符串但是ke EP的分隔符(如你在评论中提到的):
string[] arr = Regex.Split(textbox.Text, @"(?<=[.,!?])");
输入:
this is an example. Please check, and let me know your thoughts!
输出:
[0] this is an example.
[1] Please check,
[2] and let me know your thoughts!
不知道是什么问题...你是已经使用数组重载 - 所以指定更多的项目:'new Char [] {'。' ,'?','!'}' –
你的问题不清楚。你想达到什么目的?你能提供例子和期望的输出吗? –
如果我有这样的例子: 输入文本:这是一个例子。请检查,并让我知道你的想法! 所以我想从文本框中分割句子,用“。”表示。和“,”。 所以我想输出有3个数组。 ' 1.这是一个例子。 2.请检查, 3.让我知道你的想法! –