-1

i am having trouble splitting a string in c# with a delimiter of "},{".

For example the string "abc},{rfd},{5},{,},{."

Should yield an array containing:

abc
rfd
5
,
.

But I cannot seem to get it to work, even if I try RegEx I cannot get a split on the delimiter.

EDIT: Essentially I wanted to resolve this issue without the need for a Regular Expression. The solution that I accept is;

string Delimiter = "},{";  
var Result[] = StringToSplit.Split(new[] { Delimiter }, StringSplitOptions.None);

I am glad to be able to resolve this split question.

emerson.marini
  • 9,331
  • 2
  • 29
  • 46

2 Answers2

1

You can use a regular expression:

var sample = "abc},{rfd},{5},{,},{.";
var result = Regex.Split(sample, Regex.Escape("},{"));
foreach (var item in result)
    Console.WriteLine(item);
Rubens Farias
  • 57,174
  • 8
  • 131
  • 162
0

Using string array in split function

string strMultiChars = "abc},{rfd},{5},{,},{.";
//split by string array
 string[] splitByMultipleSring = strMultiChars.Split(new string[] { "},{" }, StringSplitOptions.None);
 foreach (string s in splitByMultipleSring)
 {
    Console.WriteLine(s);
  }
dotnetmirror.com
  • 293
  • 2
  • 10