0

I have a string in C# that look with pattern like this:

string Str = "!!DATA!!First!!Data!!Second!!DATA!!";

How can I split the string into array of string that contains that parts between the !!DATA!! parts?

Videron
  • 171
  • 1
  • 3
  • 11
  • 3
    Try [`String.Split()`](http://msdn.microsoft.com/en-us/library/system.string.split.aspx), or a [regular expression](http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.aspx). What did you try? – CodeCaster Sep 28 '13 at 00:45
  • The following link should provide the guidance you need ... http://stackoverflow.com/questions/1126915/how-do-i-split-a-string-by-a-multi-character-delimiter-in-c – Seymour Sep 28 '13 at 00:50

5 Answers5

4

it seems that you want a case insensitive !!DATA!! pattern the best solution for this is to use Regex

string[] data = Regex.Split(Str , "!!DATA!!",RegexOptions.IgnoreCase);
CaldasGSM
  • 3,032
  • 16
  • 26
2

Did you do any research? http://msdn.microsoft.com/en-us/library/tabh47cf.aspx

string[] data = Str.Split( new string[]{"!!DATA!!"}, StringSplitOptions.RemoveEmptyEntries )

or maybe you want

string[] data = Str.Split( new string[]{"!!DATA!!","!!Data!!"}, StringSplitOptions.RemoveEmptyEntries );
clcto
  • 9,530
  • 20
  • 42
2
string[] data = Str.Split(new string[] { "!!Data!!", "!!DATA!!" }, StringSplitOptions.RemoveEmptyEntries);
ohmusama
  • 4,159
  • 5
  • 24
  • 44
1
string[] data = yourString.Split(new string[] {"!!DATA!!"}, StringSplitOptions.RemoveEmptyEntries)

Check MSDN for further info.

pinckerman
  • 4,115
  • 6
  • 33
  • 42
-2
string[] newstring=Str.Split('!!Data!!');
SUMIT
  • 38
  • 7