5

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..

1

4 Answers 4

14

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
Sign up to request clarification or add additional context in comments.

Comments

5

You can use Regex.Split:

string[] parts = Regex.Split(text, @"\. ");

Comments

0

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);

Comments

0

Use Regular Expressions

public static void textSplitter(String text)
   {

  string pattern = "\. ";           

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

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.