• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 195,  comments - 30,  trackbacks - 0
            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

             
            ////////////////////////////////////////////////
            string[] arr = str.Split("o");

            這是一個具有語法錯誤的語句,Split 的 separator 參數應該是 char[] 或 string[],不應是字符串。正確的示例:

            string str = "technology";
            char[] separator = { 'o' };
            string[] arr = str.Split(separator);
            ////////////////////////////////////////////////////

            String.Split 方法有6個重載函數:
            程序代碼
            1) public string[] Split(params char[] separator)
            2) public string[] Split(char[] separator, int count)
            3) public string[] Split(char[] separator, StringSplitOptions options)
            4) public string[] Split(string[] separator, StringSplitOptions options)
            5) public string[] Split(char[] separator, int count, StringSplitOptions options)
            6) public string[] Split(string[] separator, int count, StringSplitOptions options)

            下邊我們通過一些實例來說明下怎么使用(以下string words = "1,2.3,,4";):
            1. public string[] Split(params char[] separator)
            程序代碼
            string[] split = words.Split(new Char[] { ',' });//返回:{"1","2.3","","4"}
            string[] split = words.Split(new Char[] { ',', '.' });//返回:{"1","2","3","","4"} 
            2. public string[] Split(char[] separator, int count)
            程序代碼
            string[] split = words.Split(new Char[] { ',', '.' }, 2);//返回:{"1","2.3,,4"}
            string[] split = words.Split(new Char[] { ',', '.' }, 6);//返回:{"1","2","3","","4"} 
            3. public string[] Split(char[] separator, StringSplitOptions options)
            程序代碼
            string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
            string[] split = words.Split(new Char[] { ',', '.' }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素 
            4. public string[] Split(string[] separator, StringSplitOptions options)
            程序代碼
            string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2","3","4"} 不保留空元素
            string[] split = words.Split(new string[] { ",", "." }, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素 
            5. public string[] Split(char[] separator, int count, StringSplitOptions options)
            程序代碼
            string[] split = words.Split(new Char[] { ',', '.' }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
            string[] split = words.Split(new Char[] { ',', '.' }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素 
            6. public string[] Split(string[] separator, int count, StringSplitOptions options)
            程序代碼
            string[] split = words.Split(new string[] { ",", "." }, 2, StringSplitOptions.RemoveEmptyEntries);//返回:{"1","2.3,,4"} 不保留空元素
            string[] split = words.Split(new string[] { ",", "." }, 6, StringSplitOptions.None);//返回:{"1","2","3","","4"} 保留空元素
            需要注意的是沒有重載函數public string[] Split(string[] separator),所以我們不能像VB.NET那樣使用words.Split(","),而只能使用words.Split(',')
            posted on 2011-03-22 15:27 luis 閱讀(1823) 評論(0)  編輯 收藏 引用
            <2009年7月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            友情鏈接

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            久久香蕉超碰97国产精品| 精品久久久久久久国产潘金莲| 国产精品免费福利久久| 国产精品一区二区久久精品| 久久久久久久综合综合狠狠| 一级做a爰片久久毛片免费陪 | 国产精品久久久亚洲| 色综合久久久久无码专区| 狠狠狠色丁香婷婷综合久久五月 | 99久久香蕉国产线看观香| 久久AV高清无码| 国产香蕉久久精品综合网| a高清免费毛片久久| 久久久久亚洲国产| 久久国产成人午夜AV影院| 人妻丰满AV无码久久不卡| 人人狠狠综合久久亚洲高清| 色综合久久中文色婷婷| 日韩人妻无码精品久久免费一 | 人妻久久久一区二区三区| 亚洲国产成人久久一区WWW| 亚洲欧美精品伊人久久| 国产精品久久久福利| 久久久久久久亚洲Av无码| 18禁黄久久久AAA片| 久久综合伊人77777| 久久久久久噜噜精品免费直播| 亚洲欧美精品伊人久久| 国产精品成人99久久久久91gav| 久久99国产精品久久| 91久久精一区二区三区大全| 97超级碰碰碰久久久久| 大伊人青草狠狠久久| 国产午夜免费高清久久影院| 久久精品aⅴ无码中文字字幕重口 久久精品a亚洲国产v高清不卡 | 久久久久国色AV免费观看| 激情综合色综合久久综合| 狠狠综合久久综合中文88| 性做久久久久久久久久久| 精品久久久久久久国产潘金莲 | 久久精品国产亚洲av影院|