比如我有一个拼凑起的字符串“hello&byebye”
现在我要分别提取hello 和 byebye字符串
用什么函数实现?
因为用substring好像不行,因为hello是不固定长的字符
c#没有java中的StringTokenizer类似的类吗?

解决方案 »

  1.   

    string s="hello&byebye";string[] sArray=s.Split('&');foreach(string i in sArray)
    Console.WriteLine(i.ToString());
      

  2.   

    楼上正解,如果分隔符不一样,可以改s.Split('&');中的参数
      

  3.   

    我自己也写了一个不知行否?
    string temp= “hello&byebye”;
    int index = temp.IndexOf("&"); 
    string fisrt=temp.Substring(0,index);
    string second=temp.Substring(index);
    System.Console.WriteLine("{0}+++{1}",fisrt,second);