使用C#进行字符串连接

Jim*_*mmy 0 c# string

我有一个输入字符串:

"风险管理,投资组合管理,投资规划"

如何将此字符串转换为:

"风险管理"+"投资组合管理"+"投资计划"

谢谢.

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)


And*_*gan 6

使用Split()方法:

string[] phrases = s.Split(',');
Run Code Online (Sandbox Code Playgroud)

现在你有一个每个逗号分隔值的字符串数组.

要删除空格,请Trim()在每个字符串上使用该方法(感谢John Feminella)