5

我有字符串string text = "1.2788923 is a decimal number. 1243818 is an integer. ";有没有办法只用逗号分割它?这意味着拆分". "而不是拆分'.'。当我尝试时,string[] sentences = text.Split(". ");我得到的方法有无效参数错误..

4

4 回答 4

13

使用String.Split Method (String[], StringSplitOptions)它来拆分它:

string[] sentences = text.Split(new string[] { ". " },StringSplitOptions.None);

您将在字符串中得到两个项目:

1.2788923 is a decimal number
1243818 is an integer
于 2013-11-05T17:38:15.973 回答
5

您可以使用Regex.Split

string[] parts = Regex.Split(text, @"\. ");
于 2013-11-05T17:36:21.057 回答
0

您拆分的字符串应位于单独的数组中。

String[] s = new String[] { ". " };
String[] r = "1. 23425".Split(s, StringSplitOptions.None);
于 2013-11-05T17:42:49.450 回答
0

使用正则表达式

public static void textSplitter(String text)
   {

  string pattern = "\. ";           

String[] sentences = Regex.Split(text, pattern);

}
于 2013-11-05T17:44:53.760 回答