我有文字
Hi, my name is <b>Dan</b> and i need/n to separate string
我需要的是通过预定义的标签找到特定的标签和单独的文本,如/ n或(b), 结果必须是:
Str[0] = Hi, my name is
Str[1] = Dan
Str[2] = and i need
Str[3] = to separate string
你能帮帮我吗?
答案 0 :(得分:1)
试试这个:
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);
答案 1 :(得分:0)
这应该可以解决问题:
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();