using System;public class SplitTest {
    public static void Main() {        string words = "this is a list of words, with: a bit of punctuation.";        string [] split = words.Split(new Char [] {' ', ',', '.', ':'});        foreach (string s in split) {            if (s.Trim() != "")
                Console.WriteLine(s);
        }
    }
}

解决方案 »

  1.   

    string类的split()方法可以用于将字符串转换为基类所提供的分隔字符串的数组
    搂住如果有c#入门经典的话
    参考608页
    有详细的介绍
      

  2.   

    s.Split(' ');得到一个字符串数组
      

  3.   

    public static StringCollection GetSplit(string Str)
            {
                System.Collections.Specialized.StringCollection sc = new StringCollection();
                //string Str = "AA  你好!  BB";
                string tmp = "";
                for (int i = 0; i < Str.Length; i++)
                {
                    if (Str[i].ToString() != " ")
                    {
                        tmp += Str[i];
                    }
                    else
                    {
                        if (tmp != "")
                            sc.Add(tmp);                    tmp = "";
                    }                if (i == Str.Length - 1 && tmp != "")
                    {
                        sc.Add(tmp);
                    }
                }
                return sc;
            }
    测试通过string Str = "AA ddddd  你好!    BB";
                StringCollection sc = MyClass.GetSplit(Str);string Str = "  AA ddddd  你好!    BB";
                StringCollection sc = MyClass.GetSplit(Str);string Str = "AA ddddd  你好!    BB    ";
                StringCollection sc = MyClass.GetSplit(Str);
      

  4.   

    正则表达式提取方法:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Text.RegularExpressions;namespace StringOperator
    {
        class Program
        {        static void Main(string[] args)
            {
                string str = "AA  你好!  BB";
                Regex reg =new Regex( @"(?<content>[\S]+)");
                if (reg.IsMatch(str))
                {
                    foreach (Match match in reg.Matches(str))
                    {
                        Console.WriteLine(match.Groups["content"].Value);
                    }
                }
                Console.ReadLine();
                
            }
        }
    }
      

  5.   

    还有问题,,这样得到的是连续的字符串;thisisalistofwords,但我想这样把this is a list of words分别赋值给str1,str2,str3,str4,str5,str6呢?