zoukankan      html  css  js  c++  java
  • C#的String.Split 方法

    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"} 保留空元素
  • 相关阅读:
    诸葛亮会议
    软件工程第十次作业——例行报告
    Beta阶段中间产物
    Beta冲刺贡献分数分配结果
    “Hello World!”团队第六周的第六次会议
    “Hello World!”团队第六周的第五次会议
    Beta发布文案+美工
    “Hello World!团队”Beta发布—视频链接+文案+美工
    软件工程第九次作业——例行报告
    “Hello World!”团队第五周第五次会议
  • 原文地址:https://www.cnblogs.com/pipizhu/p/1707252.html
Copyright © 2011-2022 走看看