c# split函数使用

vs2005使用通过:

 

using System;
using System.Collections.Generic;
using System.Text;

namespace Testsplit
{
    class Program
    {
        static void Main(string[] args)
        {
            string ls_st = "a,b,c,d,e";
            string[] arg = ls_st.Split(',');

            //for (int i = 0; i < arg.Length; i++)
            //{
            //    Console.WriteLine(arg[i].ToString());   
            //}
            foreach (string ls_arg in arg)
            {
                Console.WriteLine(ls_arg);
            }

        }
    }
}

 

输出结果:a

              b

              c

              d

              e

 

-----------------------------------------------------------------------------------

 

1 、用字符串分隔: 
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> " );



输出结果:
aaa
bbb
ccc
 

2 、用多个字符来分隔:

string  str = " aaajbbbscccjdddseee " ;

string [] sArray = str.Split( new   char [ 2 ] {'j','s'} ); 

foreach ( string  i  in  sArray) Response.Write(i.ToString()  +   " <br> " ); 



输出结果:
aaa
bbb
ccc
ddd
eee
 

3 、用单个字符来分隔:

string  str = " aaajbbbjccc " ;

string [] sArray = str.Split( ' j ' );

foreach ( string  i  in  sArray) Response.Write(i.ToString()  +   " <br> " );

输出结果:
aaa
bbb
ccc

你可能感兴趣的:(split)