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
  • 24,239
  • 7
  • 43
  • 65
David Fornas
  • 362
  • 1
  • 5
  • 18

3 Answers3

23
string[] list = b.Split(new string[] { "ab" }, StringSplitOptions.None);
Darin Dimitrov
  • 994,864
  • 265
  • 3,241
  • 2,902
12

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

 "asfsadefbweabgggggggggggg".Split(new [] {"ab" }, StringSplitOptions.None)
Joey
  • 330,812
  • 81
  • 665
  • 668
0

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

tomfanning
  • 9,442
  • 4
  • 49
  • 77