Introduction to the use of the Split function in C #

Source: Internet
Author: User

Often used in the split, here to do a systematic summary.

Split function
Role
Returns a zero-based, one-dimensional array of subscripts that contains the specified number of substrings.
Grammar
Split (expression[, delimiter[, count[, compare]])


     (2) delimiter  optional. A string character used to identify the bounds of a substring. If omitted, an empty characters (" ") is used as the delimiter. If delimiter is a zero-length string, the returned array contains only       an element, which is the complete   expression string.    
      (3) Count   optional. The number of substrings to return, and –1 indicates that all substrings are returned.   
        (4) compare   optional. A numeric value that represents the comparison method used when distinguishing substrings. For its value, see the Setting Values section.    
instance:

(1) One of the most commonly used interception methods, as follows:
String str= "1,2,3,4";
string [] strarray=str1.split (', '); Get an array of Strarray {"1", "2", "3", "4"}
foreach (string s in Strarray)
{
Response.writeline (s+ "<br/>");
}

Results

1

2

3

4

  

(2) Use multiple characters to intercept, as follows:
String str= "1,2,3,4.5";
String Strarray=strarray.split (New char[2]{', ', '. '});
foreach (string var in strarray) {
Response.writeline (var + "<br/>");
}

Output results

1

2

3

4

5

(3) using System.Text.RegularExpressions (regular expressions in a frame to intercept according to a string) such as:
String str= "Mokeybigtigerbigschool";
String[] strname= System.Text.RegularExpressions.Regex.Split (str, "big", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

foreach (string var in strName)
{
Response.writeline (var+ "<br/>");
}

Output results

Mokey

Tiger

School

Introduction to the use of the Split function in C #

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.