patterncsharpCritical
Split a string by another string in C#
Viewed 0 times
stringanothersplit
Problem
I've been using the
I've tried converting the splitter into a character array, with no luck.
In other words, I'd like to split the
THExxQUICKxxBROWNxxFOX
by
THE, QUICK, BROWN, FOX
Split() method to split strings, but this only appears to work if you are splitting a string by a character. Is there a way to split a string, with another string being the split by parameter?I've tried converting the splitter into a character array, with no luck.
In other words, I'd like to split the
string:THExxQUICKxxBROWNxxFOX
by
xx, and return an array with values:THE, QUICK, BROWN, FOX
Solution
In order to split by a string you'll have to use the string array overload.
string data = "THExxQUICKxxBROWNxxFOX";
return data.Split(new string[] { "xx" }, StringSplitOptions.None);Code Snippets
string data = "THExxQUICKxxBROWNxxFOX";
return data.Split(new string[] { "xx" }, StringSplitOptions.None);Context
Stack Overflow Q#2245442, score: 1546
Revisions (0)
No revisions yet.