• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#的String.Split方法

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

String.Split 方法有6个重载函数:ITPUB个人空间i3oMer'o[6}
ITPUB个人空间E)b'|9JU\(c

程序代码
1) public string[] Split(params char[] separator)
0^Kr9VgN7Cj `02) public string[] Split(char[] separator, int count)ITPUB个人空间a%BebPmB
3) public string[] Split(char[] separator, StringSplitOptions options)ITPUB个人空间 Ga4p h2D$j mf
4) public string[] Split(string[] separator, StringSplitOptions options)ITPUB个人空间E3J3R @yV
5) public string[] Split(char[] separator, int count, StringSplitOptions options)ITPUB个人空间T3qB7e K|g$x5O1o
6) public string[] Split(string[] separator, int count, StringSplitOptions options)

ITPUB个人空间4O+u1K Cle'O)Ne(wLU
下边我们通过一些实例来说明下怎么使用(以下string words = "1,2.3,,4";):ITPUB个人空间x5eA7C/i n:X(fI W

6@1} {/c:cf!q01. public string[] Split(params char[] separator)ITPUB个人空间3` t+e]Z]Y#KO

程序代码
string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}ITPUB个人空间I0Hf~gc0?
string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"}

ITPUB个人空间"\Ops{
2. public string[] Split(char[] separator, int count)ITPUB个人空间%qQ+aPx z:g.u9C

程序代码
string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
Cy1nM5[r0string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"}

ITPUB个人空间LK{/oz;eu
3. public string[] Split(char[] separator, StringSplitOptions options)ITPUB个人空间-u)G(w.g2n!Q,BLV_

程序代码
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素ITPUB个人空间 on^C,Fi @g O
string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素


XdZJkP/sRe04. public string[] Split(string[] separator, StringSplitOptions options)ITPUB个人空间_ ~6V?;f Ds`9c

程序代码
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素ITPUB个人空间ZAk Q%qkJ
string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素

ITPUB个人空间w@-|9CsD Lk_6w2[e
5. public string[] Split(char[] separator, int count, StringSplitOptions options)
6ji5l&HWeLN0

程序代码
string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
Cx5c,Oa TEA+r0string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素

ITPUB个人空间@)`o;]oTd c
6. public string[] Split(string[] separator, int count, StringSplitOptions options)ITPUB个人空间K9W:Sb l-t:ko

程序代码
string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
E]\4Hu%hs0string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
【C#】依赖于SharpZipLib的Zip压缩工具类发布时间:2022-07-14
下一篇:
C#中Invoke的用法1发布时间:2022-07-14
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap