How to use C#split

Source: Internet
Author: User

One, in MSDN we can see several uses

Two, let's look at the regular use,

Let's first define an array

string " 1,2,,3,4,5,6,7 ";

The first, the results are familiar to everyone, it does not explain

var a1 = Test. Split (',');  // according to, split // var a = test. Split (', ', stringsplitoptions.removeemptyentries); No, this will remove the array null values .

Third, the second use of

var a2 = Test. Split (newchar'2",'4);         // according to 2 and, character segmentation, can only be divided into four characters to create a

The results are as follows:

Then we wondered, how did these two empty come about?

1 "We intercept the first character of the string, and we get the result: 1, and, 3,4,5,6,7

2 "Again according to, to intercept 1, and, 3,4,5,6,7, to get the result is, 1," "," "and, 3,4,5,6,7,

3 "Why is four?" The reason is that the above 4 sets the length of the Intercept character

Four, the Third Kind

  var a3 = Test. Split (newchar'2','4, stringsplitoptions.removeemptyentries);     // according to 2 and, character segmentation, the array of empty values, can only be divided into four characters to create a

The results are as follows:

Then we wondered, how did the characters 3 and 4 get intercepted?

1 "The second and third kind of difference is more this empty value of the processing (stringsplitoptions.removeemptyentries), there is a null exclusion, continue to intercept the length of the set, the default is null value is not processed

2 "

Five, fourth type

var a4 = Test. Split (newchar'2',' }, stringsplitoptions.removeemptyentries);        // The null value of the array is removed according to 2 and the character segmentation

The results are as follows:

1 "The second and fourth kind of difference is the processing of the length of the character interception, by default all intercepted

Six, the fifth kind

  var a5 = test. Split (newstring"2,""5,"4 // based on 2, and 5, the string is split, the array null value is removed, can only be divided into four characters to create a

The results are as follows:

Seven, sixth type

   var a6 = test. Split (newstring"2,""5," }, stringsplitoptions.removeemptyentries);    // based on 2, and 5, string segmentation, the array empty values are removed

The results are as follows:

1 The results of the fifth and sixth are always the reason: The truncated length is three bits

2 "fifth and sixth and the other difference is that they intercept the string, while the other is the character

How to use C#split

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.