我想从一个字符串(英文句子),自动分段截取出句子里面的单词
即把英文句子的每个单词截断出来,并把每个单词存储在数组里面
要去掉空格

解决方案 »

  1.   

    string a = "this is test";string [] b = a.Split(' ');
      

  2.   

    先用正则表达式把连续的空格替换成一个,然后根据空格分隔成数组 private string[] test(string Input)
        {
            return System.Text.RegularExpressions.Regex.Replace(Input, @"[\s]+", " ").Split(' ');
        }
      

  3.   

    Mark 学习 正好要用 做C/S的数据传输 一个一个传太麻烦啦 直接从数据库里面读出来一起传
      

  4.   

    先把表点符号也替换程' ’
    然后再根据string [] b = a.Split(' ');
      

  5.   

    建议用正则表达式,下面是大概
    List<string> ret = new List<string>();
    Regex r = new Regex(@"\w+");
    Match m = r.Match(iinputstring);
    while(m.Success)
    {
      ret.Add(m.ToString());
      m = m.NextMatch;
    }
    return ret;代码是在这里手写的,有的地方可能有问题,你试一下
      

  6.   

    已测试
    string test_cmd = "hello, nice to meeting you!";
    string [] b = test_cmd.Split(' ');
      

  7.   

    应该用
    string str = "hello,nice to neeting you!";
    string[]  b = str.Split(new char[]{' ',',','!','.'}
    要把所有的标点符号都写到char[]数组中才可以取道正确的单词