! g6 z Y& A9 Q. v# j# @8 r程序代码 $ u* r* A! ~) h1) public string[] Split(params char[] separator) 8 s! d' z8 |' c+ z: i& S2) public string[] Split(char[] separator, int count) j1 B1 b; y ^/ Y
3) public string[] Split(char[] separator, StringSplitOptions options) ; c* c4 o( X q [4 F g4) public string[] Split(string[] separator, StringSplitOptions options)7 w! l8 b) Q- D
5) public string[] Split(char[] separator, int count, StringSplitOptions options), M; Y* n, m0 V% a) k
6) public string[] Split(string[] separator, int count, StringSplitOptions options)2 R+ N4 J2 Q5 s, i7 Q
2 U o' s5 Q5 o+ H" d: `2 B. ~下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):, a) k: D( K( M
- D) J6 J# ^; K' a3 H+ H; f
1. public string[] Split(params char[] separator)4 @0 F% y9 W4 X E9 ]% \: w* }
3 \7 M# Y/ X! o C1 |: n7 ~5 {8 I
程序代码# F" t0 R8 H- v! ]
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"} ( ^7 P7 g2 M# q* G0 ]string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}! S2 s9 d$ \3 s$ e! j& f9 D
x: S$ ^$ s( E' _ g9 a
2. public string[] Split(char[] separator, int count) + z1 j6 W8 g: Q! `3 C6 \2 h & ]( }$ _9 l" h# b- y6 m% a0 j 程序代码 5 s6 ~. G7 X; m8 C1 r5 ~/ A4 jstring[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"} : W/ R. J( E# N" b' }" g* \string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"} ( L& [- ~2 E5 `3 l8 U( D: S; {3 I/ y8 x7 Y- J1 U4 |; c$ w W7 ^1 q6 e( X
3. public string[] Split(char[] separator, StringSplitOptions options) 8 _! a+ T# M' l7 m' I4 S ( \! b/ Q% s T' l# N' v4 X! R 程序代码& O2 ~ Q4 o( e, h4 w5 G m+ z
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素" z& D! `8 z) G. n; U/ I# p
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素& J5 n2 u+ {4 z7 H# F/ k! v
; y; j3 v& h1 m: d5 z4. public string[] Split(string[] separator, StringSplitOptions options) 8 K$ E0 ?% U, l& b1 \3 e d' Z. ^+ D3 Y( Q y p( b7 m c
程序代码$ Q) a, N4 ]; J1 R) [3 g @/ m
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素, P" }; |/ K: C z
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素 * O. \/ G! O, E* X- x/ O+ h X7 X : J. Y3 H1 J! U* ~+ C- W: }: n8 l5. public string[] Split(char[] separator, int count, StringSplitOptions options)" N' e c! X' E0 v% ~1 T