Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split by multiple characters [duplicate]

Tags:

c#

split

The result of doing

var b = "asfsadefbweabgggggggggggg".Split("ab".ToCharArray());

is a list of 6 strings while I want to split the array in "asfsadefbwe" and "gggggggggggg". Is there any way/method to properly do that (with C#)?

PS: I'll use a string which has some data separate by "\r\n" secuences.

like image 610
David Fornas Avatar asked Jul 30 '12 09:07

David Fornas


Video Answer


2 Answers

string[] list = b.Split(new string[] { "ab" }, StringSplitOptions.None);
like image 199
Darin Dimitrov Avatar answered Nov 15 '22 03:11

Darin Dimitrov


Use another overload, one that doesn't split on individual characters:

 "asfsadefbweabgggggggggggg".Split(new [] {"ab" }, StringSplitOptions.None)
like image 27
Joey Avatar answered Nov 15 '22 02:11

Joey