string s = "a,db,dc,dd"
其中分隔字符是,d
char c = {',','d'}
我用s.Split(c)输出的不正确呀在js里split(",d")就可以得到正确的数组
上面的分隔符只是一个离子,请高手解答

解决方案 »

  1.   

    注意.net 的split方法的参数是char而不是string如果需要使用string分割字符串好像只能自己编写函数了.
      

  2.   

    - res {Length=8} string[]
    [0] "a" string
    [1] "" string
    [2] "b" string
    [3] "" string
    [4] "c" string
    [5] "" string
    [6] "" string
    [7] "" string
      

  3.   

    // 注意 .net 的 string.Split() 方法的参数是 char 而不是 string
    // 如果需要使用 string 分割字符串就请用 Regex.Split() 方法, heheusing System;
    using System.Text.RegularExpressions;public class Test
    {
      public static void Main()
      {
        string aStr = "a,db,dc,dd";
        string [] split = Regex.Split(aStr, ",d");
        foreach (string s in split)
        {
          Console.WriteLine(s);
        }
      }
    }/* 程序输出:
    a
    b
    c
    d
    */
      

  4.   

    string s = "a,db,dc,dd";
    string[] c = s.Split(',','d');
    for(int i=0;i<c.Length ;i++)
    {
        this.label1.Text += c[i];
    }
      

  5.   

    string s = "a,db,dc,dd";
    s=s.Replace(",d",",");
    string[] res=s.Split(',');
    ===========================================================- res {Length=4} string[]
    [0] "a" string
    [1] "b" string
    [2] "c" string
    [3] "d" string
      

  6.   

    string s = "a,db,dc,dd";
    s=s.Replace(",d",",");
    string[] res=s.Split(',');
    ===========================================================To: jinjazz(近身剪(充电中...)):要是源串中含 ',' 呢? 或者说源串比较长, 可能包含你用来替换的任何字符呢?
    有现成的 Regex.Split() 可以用字符串分隔, 有什么道理不用呢?
      

  7.   

    string s = "a,db,dc,dd"
    其中分隔字符是,d
    string[] ss = s.split('d');
    for(int i=0;i<ss.Length;i++)
    {
    Response.Write(ss[i].ToString()+"**");
    }