-5

I have text

Hi, my name is <b>Dan</b> and i need/n to separate string

What I need is to find specific tags and separate text by predefined tags like /n or (b), the result need to be:

Str[0] = Hi, my name is
Str[1] = Dan
Str[2] = and i need
Str[3] = to separate string

Can you please help me?

Core-One
  • 466
  • 2
  • 6
  • 19
Dim
  • 4,527
  • 15
  • 80
  • 139
  • 1
    Did your have a look at Regex.Split? ( http://msdn.microsoft.com/de-de/library/ze12yx1d(v=vs.110).aspx ) – Chrisi Jul 24 '14 at 11:14
  • the String.Split accept an array of delimiter that you specify to split on. if you give it `new [] {"a","b"}` as the array delimiter the following `this blueberry is on the table` will give `[]{"this ","lue","erry is on the t","ble"}` splitting for any `a` or `b` – Franck Jul 24 '14 at 11:23
  • Do you mean "/n" or "\n"? – Enigmativity Jul 24 '14 at 11:28
  • 1
    *Did you have a look at `Regex.Split`?*... clearly, this user didn't look at anything, or make any effort themselves before asking this question. -1 – Sheridan Jul 24 '14 at 11:41
  • possible duplicate of [How do I split a string by a multi-character delimiter in C#?](http://stackoverflow.com/questions/1126915/how-do-i-split-a-string-by-a-multi-character-delimiter-in-c) – Anton Semenov Jul 24 '14 at 13:21

2 Answers2

1

Try this :

string[] separators = {"<b>", "</b>", "\\n"};
string value = "Hi, my name is <b>Dan</b> and i need \\n to separate string";
string[] words = value.Split(separators, StringSplitOptions.RemoveEmptyEntries);
Vishal
  • 6,238
  • 10
  • 82
  • 158
0

This should do the trick:

const string source = "hi, my name is <b>Dan</b> and i need/n to separate string";
var res = Regex.Split(source, "(</?b>)|(/n)").Where(x => !Regex.IsMatch(x, "(</?b>)|(/n)")).ToArray();
Chrisi
  • 371
  • 3
  • 15