- Home /
Splitting a string using a string
I have seen several threads in different forums that deal with string splitting, and saw in particular that in a few of them was stated that you could only split with a char.
Answer by roamcel · Aug 06, 2011 at 06:35 AM
Fortunately, as detailed here: http://msdn.microsoft.com/en-us/library/tabh47cf%28v=VS.90%29.aspx
you can split a string using a string, as long as you declare it as an array!
// Split a string delimited by another string and return all elements.
string[] result = source.Split(stringSeparators, StringSplitOptions.None);
where
string[] stringSeparators = new string[] {"[stop]"};
hopefully this post will save the time of those poor fools like me that didn't want to use regular expressions to do such a simple string operation.
I had to add System to StringSplitOptions to get it to work, like this:
string[] result = source.Split(new string[] {"[stop]"}, System.StringSplitOptions.None);
Your answer

Follow this Question
Related Questions
StringSplitOptions.RemoveEmptyEntries - Unknown identifier 2 Answers
issues splitting strings 1 Answer
Extract number from string? 3 Answers
Split a string every 'n' characters? 5 Answers
How to split a string into array? 2 Answers