Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# splitting strings using string instead of char as seperator

Tags:

c#

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

like image 655
Martin Dzhonov Avatar asked Nov 05 '13 17:11

Martin Dzhonov


2 Answers

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
like image 167
Habib Avatar answered Sep 27 '22 02:09

Habib


You can use Regex.Split:

string[] parts = Regex.Split(text, @"\. ");
like image 29
knittl Avatar answered Sep 25 '22 02:09

knittl