Split applications in C # partition string (C #, Split, separated, string) enumeration of the RegexOptions

1, separated by the string:

using System.Text.RegularExpressions;
string str="aaajsbbbjsccc";
string[] sArray=Regex.Split(str,"js",RegexOptions.IgnoreCase);
foreach (string i in sArray) Response.Write(i.ToString() + "<br>"); 

 Output:
aaa
bbb
ccc
 

2, separated by a plurality of characters:

string str="aaajbbbscccjdddseee";

string[] sArray=str.Split(new char[2]{'j','s'}); 
foreach(string i in sArray) Response.Write(i.ToString() + "<br>");  


 Output Results:
AAA
BBB
CCC
ddd
Eee
 
. 3, a single character to separate:

string str="aaajbbbjccc";
string[] sArray=str.Split('j');
foreach(string i in sArray) Response.Write(i.ToString() + "<br>")


  Output:
aaa
bbb

   ccc

 

  When creating an instance of the Regex class, overloaded constructor there is a requirement to pass a enumeration value RegexOptions, I believe this will be very useful to enumerate it will not seek passed in the constructor. Today, we take a look at the role of the enumeration.

  We simply look to knock out the code:

None = 0, // do not specify setup options. 
IgnoreCase = 1, // the specified insensitive matching. 
Multiline = 2, // multiline mode. Change the meaning of ^ and $ so they match at each end of the line beginning of the line and any line, not just at the beginning and end of the match the entire string. 
ExplicitCapture = 4, // specify a valid capture only the form (? <Name> ...) groups explicitly named or numbered. This allows unnamed parentheses to act as a non-capturing group, and not the expression syntax (:? ...) is clumsy. 
Compiled = 8, // specified regular expression compiled into an assembly. This results in faster execution but increases startup time. When calling System.Text.RegularExpressions.Regex.CompileToAssembly (System.Text.RegularExpressions.RegexCompilationInfo [], System.Reflection.AssemblyName) method, this value should be assigned to the attribute. 
Singleline = 16, // specified single-line mode. Change the point (.) Meaning that it (and not match with each character except \ n's) match with each character. 
IgnorePatternWhitespace = 32 // elimination mode and enable non-blank escaped marked by # of comments. However, System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace value does not affect or eliminate white space character class.
RightToLeft = 64 // specify the search from right to left instead of left to right.
ECMAScript = 256, // enable ECMAScript-compliant behavior for the expression. This value can only use the System.Text.RegularExpressions.RegexOptions.IgnoreCase System.Text.RegularExpressions.RegexOptions.Multiline and System.Text.RegularExpressions.RegexOptions.Compiled values together. This value is used in conjunction with any other values are will result in an exception. 
CultureInvariant = 512 // Specify ignore regional differences in language.

  When creating an instance of the Regex class, overloaded constructor there is a requirement to pass a enumeration value RegexOptions, I believe this will be very useful to enumerate it will not seek passed in the constructor. Today, we take a look at the role of the enumeration.

  We simply look to knock out the code:

None = 0, // do not specify setup options. 
IgnoreCase = 1, // the specified insensitive matching. 
Multiline = 2, // multiline mode. Change the meaning of ^ and $ so they match at each end of the line beginning of the line and any line, not just at the beginning and end of the match the entire string. 
ExplicitCapture = 4, // specify a valid capture only the form (? <Name> ...) groups explicitly named or numbered. This allows unnamed parentheses to act as a non-capturing group, and not the expression syntax (:? ...) is clumsy. 
Compiled = 8, // specified regular expression compiled into an assembly. This results in faster execution but increases startup time. When calling System.Text.RegularExpressions.Regex.CompileToAssembly (System.Text.RegularExpressions.RegexCompilationInfo [], System.Reflection.AssemblyName) method, this value should be assigned to the attribute. 
Singleline = 16, // specified single-line mode. Change the point (.) Meaning that it (and not match with each character except \ n's) match with each character. 
IgnorePatternWhitespace = 32 // elimination mode and enable non-blank escaped marked by # of comments. However, System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace value does not affect or eliminate white space character class.
RightToLeft = 64 // specify the search from right to left instead of left to right.
ECMAScript = 256, // enable ECMAScript-compliant behavior for the expression. This value can only use the System.Text.RegularExpressions.RegexOptions.IgnoreCase System.Text.RegularExpressions.RegexOptions.Multiline and System.Text.RegularExpressions.RegexOptions.Compiled values together. This value is used in conjunction with any other values are will result in an exception. 
CultureInvariant = 512 // Specify ignore regional differences in language.

Guess you like

Origin www.cnblogs.com/siyunianhua/p/11353899.html