string Split function using method sharing

Source: Internet
Author: User
Tags foreach array length regular expression split

  This article mainly introduces the use of string segmentation function, the need for friends can refer to the following

Let's take a look at a simple example   but its array length is 25 instead of 3. The following approach is to first replace "[]" with a special character, such as $, which performs a split   based on this character, such as the following according to [] split     code as follows: string[] arrstr2 = str. Replace ("[]", "$"). Split (' $ ');     Look at other methods, the simplest and most commonly used methods, split with a specified character open create a new console project. Then enter the following program under the main () method.     Code as follows: String s= "ABCDEABCDEABCDE";  string[] sarray=s.split (' C ');  foreach (String i in Sarray) & nbsp Console.WriteLine (i.ToString ());     Output The following results:      code as follows: ab  deab  deab  de     2, split with multiple characters     The code is as follows: String s= "ABCDEABCDEABCDE"   string[] sarray1=s.split (new char[3]{' C ', ' d ', ' e '});  foreach (String i in SArray1)   Console.WriteLine (i.ToString ());     Output The following results:    code as follows: ab  ab  AB     3, use regular expression   Add reference     code as follows: using System.Text.RegularExpressions;   String content= "Agcsmallmacsmallgggsmallytx";  string[]resultstring=regex.split (Content, "small", Regexoptions.ignorecase)   foreach (String i in Resultstring)   Console.WriteLine (i.ToString ());       Output The following results:    code as follows: agc  mac  ggg  ytx     There is a less common method of the   code as follows: String str = "Reterry[]" is the webmaster of the Script House [];  string[] arrstr = str. Split (new char[] {', ' s ', ' o ', ' s ', ' u ', ' O ', ' 8 ', '. ', ' C ', ' O ', ' m ', ', '} ';  for (int i = 0; i < Arrstr. Length; i++)   {  Response.Write (Arrstr[i]); }  
Related Article

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: 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.