代码之家  ›  专栏  ›  技术社区  ›  Alon Gubkin

C#-字符串到关键字

  •  4
  • Alon Gubkin  · 技术社区  · 14 年前

    例如:

    Hello... world 1, this is amazing3,really ,  amazing! *bla*
    

    应转换为以下字符串列表:

    ["Hello", "world", "1", "this", "is", "amazing3", "really", "amazing", "bla"]
    

    请注意,它应该支持英语以外的其他语言。

    我需要这个,因为我想收集特定文本的关键字列表。

    3 回复  |  直到 13 年前
        1
  •  5
  •   Brian Gideon    14 年前

    使用正则表达式怎么样?你可以让表达式任意复杂,但我这里的内容应该适用于大多数输入。

    new RegEx(@"\b(\w)+\b").Matches(text);
    
        2
  •  5
  •   James Curran    14 年前
    char[] separators = new char[]{' ', ',', '!', '*', '.'};  // add more if needed
    
    string str = "Hello... world 1, this is amazing3,really ,  amazing! *bla*";
    string[] words= str.Split(separators, StringSplitOptions.RemoveEmptyEntries);
    
        3
  •  2
  •   Hans Passant    14 年前