您的位置:首页 > 编程语言 > C#

C#中split的5种方法

2009-03-16 18:05 295 查看
C#中split的5种方法
第一种方法:

string s=abcdeabcdeabcde;

string[] sArray=s.Split('c') ;

foreach(string i in sArray)

Console.WriteLine(i.ToString());

输出下面的结果:

ab

deab

deab

de

第二种方法:

我们看到了结果是以一个指定的字符进行的分割。使用另一种构造方法对多个字符进行分割:

string s="abcdeabcdeabcde";

string[] sArray1=s.Split(new char[3]{'c','d','e'}) ;

foreach(string i in sArray1)

Console.WriteLine(i.ToString());

可以输出下面的结果:

ab

ab

ab

第三种方法:

除了以上的这两种方法以外,第三种方法是使用正则表达式。新建一个控制台项目。然后先添加 using System.Text.RegularExpressions;

System.Text.RegularExpressions

string content=agcsmallmacsmallgggsmallytx;

string[]resultString=Regex.Split(content,small,RegexOptions.IgnoreCase)

foreach(string i in resultString)

Console.WriteLine(i.ToString());

输出下面的结果:

agc

mac

ggg

ytx

第四种方法:

string str1=我*****是*****一*****个*****教*****师;

string[] str2;

str1=str1.Replace(*****,*) ;

str2=str1.Split(*) ;

foreach(string i in str2)

Console.WriteLine(i.ToString());

第五种方法:

string str1=我**是*****一*****个*****教*****师;

我希望显示的结果为:我是一个教师。

我如果采用上面的第四种方法来做就会产生下面的错误:我 是一个教师。中间有空格输出,所以输出结果并不是希望的结果,这就又回到了正则表达式了,这时可以采用下面的第五种方法:

string str1=我**是*****一*****个*****教*****师;

string[] str2 = System.Text.RegularExpressions.Regex.Split(str1,@[*]+);

foreach(string i in str2)

Console.WriteLine(i.ToString());

这里通过[*]+ 巧妙的完成了我们的目标。

http://dl.vmall.com/c07ns310pm

http://dl.vmall.com/c0luky7sre

http://dl.vmall.com/c0ytpi0ehe

http://dl.vmall.com/c0x61ubae5

http://dl.vmall.com/c0n445f2sq

http://dl.vmall.com/c0q43uvkaa

http://dl.vmall.com/c0e7y6xpar

http://dl.vmall.com/c082sxejci

http://dl.vmall.com/c0igeb4fri

http://dl.vmall.com/c0djjo3fc5

http://dl.vmall.com/c0fyqm9tba

http://dl.vmall.com/c0qg18zce3

http://dl.vmall.com/c0x0e2pwpw

http://dl.vmall.com/c0rf0b5uub

http://dl.vmall.com/c01jsnq26n

http://dl.vmall.com/c0ohiztx36

http://dl.vmall.com/c0fktd837j

http://dl.vmall.com/c0o5f6q56u

http://dl.vmall.com/c0izo66a0r

http://dl.vmall.com/c0i6wr4a4u

http://dl.vmall.com/c0qb0ghl41

http://dl.vmall.com/c0gruq8ihg

http://dl.vmall.com/c0zfs0hhxt

http://dl.vmall.com/c0rx0hfgpr

http://dl.vmall.com/c0b42wotte

http://dl.vmall.com/c07aaugud9

http://dl.vmall.com/c0nehba52t

http://dl.vmall.com/c006y8vukq

http://dl.vmall.com/c0y15aw6yh

http://dl.vmall.com/c0y7ccfmc6

http://dl.vmall.com/c0pgq0o0am

http://dl.vmall.com/c0i1xg2pv1

http://dl.vmall.com/c01ljsleay

http://dl.vmall.com/c05ueeazev

http://dl.vmall.com/c0wopudovx

http://dl.vmall.com/c0kwkuo7m2

http://dl.vmall.com/c08nytf1bm

http://dl.vmall.com/c0xgfzl8mf

http://dl.vmall.com/c0s5vhm4d3

http://dl.vmall.com/c074vp2gab

http://dl.vmall.com/c0ij54vez6

http://dl.vmall.com/c03iftrwdt

http://dl.vmall.com/c08zxa98wa

http://dl.vmall.com/c0c4palab0

http://dl.vmall.com/c0t09v0lqn

http://dl.vmall.com/c093mpcap3

http://dl.vmall.com/c03rk461a7

http://dl.vmall.com/c0rfckpasd

http://dl.vmall.com/c0iz9lsz2y

http://dl.vmall.com/c0gwsviq4t

http://dl.vmall.com/c01b6ad0hr

http://dl.vmall.com/c0vfszu28n

http://dl.vmall.com/c0vdtr887h

http://dl.vmall.com/c0dozkyaah

http://dl.vmall.com/c0c3g85cly

http://dl.vmall.com/c0qlxcs2jc

http://dl.vmall.com/c0204ckexh

http://dl.vmall.com/c0a4y3czrg

http://dl.vmall.com/c0yhfg2jaj

http://dl.vmall.com/c0va1dp90z

http://dl.vmall.com/c0febvqo1d

http://dl.vmall.com/c0chfce6aq

http://dl.vmall.com/c0af75a7tn

http://dl.vmall.com/c0z6qv9va3

http://dl.vmall.com/c0m31ggk5x

http://dl.vmall.com/c0iibrdkhu

http://dl.vmall.com/c0ntrh3krx

http://dl.vmall.com/c0pwkk2ljr

http://dl.vmall.com/c0yh31xtpe

http://dl.vmall.com/c021znsvob

http://dl.vmall.com/c0slp8b6rx

http://dl.vmall.com/c0milsgu4e

http://dl.vmall.com/c0gcp99k6y

http://dl.vmall.com/c0noj9yz3v

http://dl.vmall.com/c0fw87efc5

http://dl.vmall.com/c002w8u1nm

http://dl.vmall.com/c0js3yl5n6

http://dl.vmall.com/c06j1ffz0a

http://dl.vmall.com/c0r6anyx73

http://dl.vmall.com/c072n28e6h

http://dl.vmall.com/c03o3kyyy8

http://dl.vmall.com/c0dsr8a3gf

http://dl.vmall.com/c0p4hwapox

http://dl.vmall.com/c0oe1au7yc

http://dl.vmall.com/c0axdxf6zf

http://dl.vmall.com/c0niv9wsv2

http://dl.vmall.com/c0rpbw7yx1

http://dl.vmall.com/c080bnspmd

http://dl.vmall.com/c0srde252w

http://dl.vmall.com/c0beji556v

http://dl.vmall.com/c0ytgjz6aa

http://dl.vmall.com/c08sibnf2m

http://dl.vmall.com/c0dm3qk2t3

http://dl.vmall.com/c0a2kt4z5j

http://dl.vmall.com/c0caewynfw

http://dl.vmall.com/c05afpnzt3

http://dl.vmall.com/c09fv3dowl

http://dl.vmall.com/c06o7dw5by

http://dl.vmall.com/c0ceynq9x6

http://dl.vmall.com/c0ujha5p0c

http://dl.vmall.com/c0djokpgxd

http://dl.vmall.com/c0ytto22uk

http://dl.vmall.com/c06y1hq2y4

http://dl.vmall.com/c040xkr1aw

http://dl.vmall.com/c0keetxxzz

http://dl.vmall.com/c0oh5d3tz6

http://dl.vmall.com/c0ge1ywl7f

http://dl.vmall.com/c0afujwrrb

http://dl.vmall.com/c0o28d3zis

http://dl.vmall.com/c0e2pyl0mj

http://dl.vmall.com/c0aq1lalnh

http://dl.vmall.com/c0lhbrq2p4

http://dl.vmall.com/c0cwvt6pft

http://dl.vmall.com/c0baj8caq0

http://dl.vmall.com/c0h6piqdxi

http://dl.vmall.com/c0v4yn0ex5

http://dl.vmall.com/c0p6q892vq

http://dl.vmall.com/c0rpwzh44n

http://dl.vmall.com/c0bjtibqmo

http://dl.vmall.com/c001v6rwq9

http://dl.vmall.com/c0xos5dgn7

http://dl.vmall.com/c08pesmspy

http://dl.vmall.com/c0d6a1y2hc

http://dl.vmall.com/c0wix6l9eb

http://dl.vmall.com/c0owsxgrw9

http://dl.vmall.com/c0hpoy3sf9

http://dl.vmall.com/c028v5ns6c

http://dl.vmall.com/c0ta4p3fy2

http://dl.vmall.com/c0w0w2gl0j

http://dl.vmall.com/c0s3ypzvbp

http://dl.vmall.com/c0gjnzvab9

http://dl.vmall.com/c08dsuggzc

http://dl.vmall.com/c03dtp64v5

http://dl.vmall.com/c0p5xex3oo

http://dl.vmall.com/c0van3v44a

http://dl.vmall.com/c0wlenx7on

http://dl.vmall.com/c0bxrfq6pg

http://dl.vmall.com/c0vzb44jo3

http://dl.vmall.com/c0kt7529mh

http://dl.vmall.com/c0w9rhdst6

http://dl.vmall.com/c04gtm8cli

http://dl.vmall.com/c0bfc7kq3m

http://dl.vmall.com/c0wsjpxmf3

http://dl.vmall.com/c0au42jga1

http://dl.vmall.com/c09b3yxnlv

http://dl.vmall.com/c0gm33a15u

http://dl.vmall.com/c0wkje6voi

http://dl.vmall.com/c0ss9ujdni

http://dl.vmall.com/c06nnieavu

http://dl.vmall.com/c0wklpwlot

http://dl.vmall.com/c03ksodf23

http://dl.vmall.com/c0ao38x0bf

http://dl.vmall.com/c0m5ldbgf1

http://dl.vmall.com/c0nypq4o84

http://dl.vmall.com/c0agdlfn6g

http://dl.vmall.com/c09qdzge45

http://dl.vmall.com/c0mfynmpgs

http://dl.vmall.com/c05ilmeu7t

http://dl.vmall.com/c0xxaqdehs

http://dl.vmall.com/c0jzuyo515

http://dl.vmall.com/c0v0y2o10c

http://dl.vmall.com/c07jt7ar7o

http://dl.vmall.com/c0oaawahxs

http://dl.vmall.com/c0ckpuyzw6

http://dl.vmall.com/c0ltk6gvv0

http://dl.vmall.com/c08tfy44km

http://dl.vmall.com/c0sna6h1xi

http://dl.vmall.com/c0baoezd4k

http://dl.vmall.com/c0dfm48v6a

http://dl.vmall.com/c0jhsivp5k

http://dl.vmall.com/c02u8kxu8d

http://dl.vmall.com/c0wgvj8i4a

http://dl.vmall.com/c0ps0y002a

http://dl.vmall.com/c0fb53ngae

http://dl.vmall.com/c0a5tbn7pu

http://dl.vmall.com/c0ybbc2y9g

http://dl.vmall.com/c0q9y3xp1j

http://dl.vmall.com/c0kecmv227

http://dl.vmall.com/c0glzqb7px

http://dl.vmall.com/c0ok42a3np

http://dl.vmall.com/c0iqwhm6zg

http://dl.vmall.com/c018cda3ui

http://dl.vmall.com/c0pi2nd1ui

http://dl.vmall.com/c0eujcu6rp

http://dl.vmall.com/c0tv2wau7g

http://dl.vmall.com/c0kj498qla

http://dl.vmall.com/c07sele9si

http://dl.vmall.com/c05zl79p9t

http://dl.vmall.com/c0ej6pvwht

http://dl.vmall.com/c0gf3009ps

http://dl.vmall.com/c0tkbfk696

http://dl.vmall.com/c0tzxp0hg1

http://dl.vmall.com/c0itg9mdx7

http://dl.vmall.com/c0qczgylnm

http://dl.vmall.com/c0lu7i8plb

http://dl.vmall.com/c0wipebhv3

http://dl.vmall.com/c0oaafva52

http://dl.vmall.com/c0xvwgoke5

http://dl.vmall.com/c0p08zha3r

http://dl.vmall.com/c0lnvv2as1

http://dl.vmall.com/c0arzslm0n

http://dl.vmall.com/c06q5c0qw1

http://dl.vmall.com/c0s0ax1poo

http://dl.vmall.com/c0hs35lgk7

http://dl.vmall.com/c0amxxptpp

http://dl.vmall.com/c0cj7vnbt3

http://dl.vmall.com/c0inygtzk7

http://dl.vmall.com/c01hgef20r

http://dl.vmall.com/c0xxny28ga

http://dl.vmall.com/c0i5e0tsxr

http://dl.vmall.com/c0bfiow4lh

http://dl.vmall.com/c0zahnr5hl

http://dl.vmall.com/c05g8ygqhc

http://dl.vmall.com/c0cm9emnxx

http://dl.vmall.com/c0r6dr3h01

http://dl.vmall.com/c0k3ru1x1m

http://dl.vmall.com/c05h6i24wh

http://dl.vmall.com/c0w65awdmc

http://dl.vmall.com/c062dbao7w

http://dl.vmall.com/c0podyzlae

http://dl.vmall.com/c0cie6c6y3

http://dl.vmall.com/c0xa6hpqad

http://dl.vmall.com/c0xkf97i6h

http://dl.vmall.com/c0pcfpzk8p

http://dl.vmall.com/c03jc3483p

http://dl.vmall.com/c0m97ch26o

http://dl.vmall.com/c0psculimv

http://dl.vmall.com/c0c0c7qaac

http://dl.vmall.com/c0bv2cafzz

http://dl.vmall.com/c0nhavxtyo

http://dl.vmall.com/c03lfknfz6

http://dl.vmall.com/c0lcamb7mm

http://dl.vmall.com/c012a6xp1x

http://dl.vmall.com/c0zezqlszi

http://dl.vmall.com/c0dbx8vqo4

http://dl.vmall.com/c0czalacaw

http://dl.vmall.com/c0wetsyie9

http://dl.vmall.com/c0c5cq1td9

http://dl.vmall.com/c0s0l7al8t

http://dl.vmall.com/c0amilt36c

http://dl.vmall.com/c0c1mrhvqr

http://dl.vmall.com/c0zrud6zzu

http://dl.vmall.com/c0b4t2lw6w

http://dl.vmall.com/c0apr13eyk

http://dl.vmall.com/c0jszbdjk9

http://dl.vmall.com/c0f58ygghy

http://dl.vmall.com/c0vyoj76h3

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: