我有一个输入字符串:
"风险管理,投资组合管理,投资规划"
如何将此字符串转换为:
"风险管理"+"投资组合管理"+"投资计划"
谢谢.
// include linq library like this: // using System.Linq; // then "test1, test2".Split(',').Select(o => o.Trim());
要么
"test1, test2".Split(',').Select(o => o.Trim()).ToArray(); // returns array
和
"test1, test2".Split(',').Select(o => "\"" + o.Trim() + "\"") .Aggregate((s1, s2) => s1 + " + " + s2); // returns a string: "test1" + "test2"
使用Split()
方法:
string[] phrases = s.Split(',');
现在你有一个每个逗号分隔值的字符串数组.
要删除空格,请Trim()
在每个字符串上使用该方法(感谢John Feminella)