I have string string text = "1.2788923 is a decimal number. 1243818 is an integer. ";
Is there a way to split it on the commas only ? This means to split on ". "
but not on '.'
. When I try string[] sentences = text.Split(". ");
I get method has invalid arguments error..
Use String.Split Method (String[], StringSplitOptions)
to split it like:
string[] sentences = text.Split(new string[] { ". " },StringSplitOptions.None);
You will end up with two items in your string:
1.2788923 is a decimal number
1243818 is an integer
你可以使用Regex.Split
:
string[] parts = Regex.Split(text, @"\. ");
The string(s) that you splitting on are expected to be in a separate array.
String[] s = new String[] { ". " };
String[] r = "1. 23425".Split(s, StringSplitOptions.None);
Use Regular Expressions
public static void textSplitter(String text)
{
string pattern = "\. ";
String[] sentences = Regex.Split(text, pattern);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.