5

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.

Shai
  • 25,159
  • 9
  • 44
  • 67
David Fornas
  • 362
  • 1
  • 5
  • 18

3 Answers3

23
string[] list = b.Split(new string[] { "ab" }, StringSplitOptions.None);
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
12

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

 "asfsadefbweabgggggggggggg".Split(new [] {"ab" }, StringSplitOptions.None)
Joey
  • 344,408
  • 85
  • 689
  • 683
0

Are your substrings always the same length? If so, use String.Substring.

tomfanning
  • 9,552
  • 4
  • 50
  • 78