Alo*_*kin 4 c# string list keyword
将字符串转换为C#中的单词列表的最有效方法是什么?
例如:
Hello... world 1, this is amazing3,really , amazing! *bla*
Run Code Online (Sandbox Code Playgroud)
应该变成以下字符串列表:
["Hello", "world", "1", "this", "is", "amazing3", "really", "amazing", "bla"]
Run Code Online (Sandbox Code Playgroud)
请注意,它应该支持除英语之外的其他语言.
我需要这个,因为我想从特定文本中收集关键字列表.
谢谢.
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);
Run Code Online (Sandbox Code Playgroud)
如何使用正则表达式?你可以使表达式任意复杂,但我在这里应该适用于大多数输入.
new RegEx(@"\b(\w)+\b").Matches(text);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
154 次 |
最近记录: |