you can do this first; str.Separator.Replace(".",@"\.").Replace("?",@"\?").. and so on then do you work Regex rg = new Regex(strSeparator); string[] strArr = rg.Split(stringInput);
another way,you can use the String.Split method to separater your stringmore reference:ms-help://MS.VSCC/MS.MSDNVS.2052/cpref/html/frlrfSystemStringClassSplitTopic.htmon this way,you only need convert the strSeparator to a char arry
str.Separator.Replace(".",@"\.").Replace("?",@"\?").. and so on then do you work Regex rg = new Regex(strSeparator); string[] strArr = rg.Split(stringInput);
"He is a boy\.Today is Tuesday\."
或
@"He is a boy.Today is Tuesday."
str.Separator.Replace(".",@"\.").Replace("?",@"\?").. and so on
then do you work
Regex rg = new Regex(strSeparator);
string[] strArr = rg.Split(stringInput);
此外是不能用string.split方法做,因为string.split只能单个char地分,而我这里是允许根据一个字符串分割的
比方说abcdbc允许用bc分割成a,d 的
你只有把正则表达式中的特殊字符
全部都写到str.Separator.Replace(".",@"\.").Replace("?",@"\?").. and so on
中去
如果有,就加上\转译
没有的话,也没有影响正则表达式的类中好像没有提供这种方法
好像只能这么做了
你说的有道理
我找了一下
有一个方法Regex.Escape
通过替换为转义码来转义最小的元字符集(\、*、+、?、|、{、[、(、)、^、$、.、# 和空白)。ms-help://MS.VSCC/MS.MSDNVS.2052/cpref/html/frlrfsystemtextregularexpressionsregexclassescapetopic.htm
then do you work
Regex rg = new Regex(strSeparator);
string[] strArr = rg.Split(stringInput);