Kon*_*kus 18
// include linq library like this:
// using System.Linq;
// then
"test1, test2".Split(',').Select(o => o.Trim());
Run Code Online (Sandbox Code Playgroud)
要么
"test1, test2".Split(',').Select(o => o.Trim()).ToArray(); // returns array
Run Code Online (Sandbox Code Playgroud)
和
"test1, test2".Split(',').Select(o => "\"" + o.Trim() + "\"")
.Aggregate((s1, s2) => s1 + " + " + s2);
// returns a string: "test1" + "test2"
Run Code Online (Sandbox Code Playgroud)
使用Split()方法:
string[] phrases = s.Split(',');
Run Code Online (Sandbox Code Playgroud)
现在你有一个每个逗号分隔值的字符串数组.
要删除空格,请Trim()在每个字符串上使用该方法(感谢John Feminella)