直接为Split()提供“用以分割字符串”的一串字符。
string[] str;
string s=",11,22,33,44";
char[] c={';', ','}//数字之间的标点符号
str=s.Split(c)

解决方案 »

  1.   

    string temp=",11,22,33,44";
    string [] result=temp.Split(',');
      

  2.   

    string temp=",11,22,33,44";
    string [] result=temp.Split(',');
    ArrayList RecvDb = new ArrayList();
    foreach(string option  in result)
    {
    if (option.Length > 0)
            {
     RecvDb.Add(option);
    }
    }
    Split()函数可以分隔字符串,但是,我用楼上的代码生成的数组result[0]为空,而不是应该得到的11,所以需要去掉空字符,但是对一个字符串,当我不知道楼主是不是需要去掉控字符,如果需要的话,很可能一个字符串出现多个空字符,所以其长度就不能确定,也就没办发直接产一个字符串数组,而是产生了一个ArrayList,不知道我的做法是不是多此一举
      

  3.   

    13880079673(CMonkey)  is right.One way is to remove the first comma of the string temp:string [] result=temp.Remove(0,1).Split(',');-or-
     to resort to Regular expression,try:using System;
    using System.Collections;
    using System.Text.RegularExpressions;class Work{
     static void Main(){
    string temp=",11,22,33,44";
    Regex r = new Regex(@",(\d+)");
    ArrayList RecvDb = new ArrayList();
    Match m = r.Match(temp);
    while(m.Success){
      RecvDb.Add(m.Groups[1].ToString());
      m = m.NextMatch();
    }
    foreach(string s in RecvDb)
      Console.WriteLine(s);
    }
    }