Difference between Str. Split and RegEx. Split

Source: Internet
Author: User

Str. Split andRegEx. Split. In my experience, it is a simple replacement of a single string, directly using a string. split ('single string'). Replace multiple strings with RegEx. split (string, @ "multiple strings ",Regexoptions. ignorecase). Here are two examples.
Example 1

1 String Strsample = " 11,22, 33,44, 55,66 " ;
2 String [] Sarray = Strsample. Split ( ' , ' ); // Note: here we use single quotes instead of double quotes.
3 Response. Write (sarray [ 0 ]); // Here, when the value in sarray [0] is 0, 11 is displayed. When the value is 1, 22 is displayed.

Example 2

1 Using System. Text. regularexpressions; // This reference cannot be less, because the RegEx used is in this class.
2 String Strsample = " AAA <sample> BB <sample> CC " ;
3 String [] Sarray = RegEx. Split (strsample, @" /<Sample/> " , Regexoptions. ignorecase ); // The following statement can also be used here, but it is better to use this statement from the perspective of code robustness. As for @ and/, the function is to escape,A string defined by @ is treated as a common character. escape characters are not escaped.It is worth noting that double quotation marks are used here, not single quotation marks.
4 // String [] sarray = RegEx. Split (strsample, "<sample>", regexoptions. ignorecase );
5 Response. Write (sarray [ 0 ]);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.