C# 如何合并我拆分的字符串?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/713476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 22:10:54  来源:igfitidea点击:

How can I merge back a string I split?

c#string

提问by

I like how I can do string [] stringArray = sz.split('.');

我喜欢我能做什么 string [] stringArray = sz.split('.');

but is there a way to merge them back together? (stringArray.Merge(".");)

但是有没有办法将它们合并在一起? (stringArray.Merge(".");)

采纳答案by Miha Markic

String.Join

字符串连接

回答by Mitch Wheat

String.Join()

回答by Tamas Czinege

string mergedString = String.Join(" ", stringArray);

回答by sovan

Suppose there is a phone number like:

假设有一个电话号码,例如:

string str = "^^^^^546^64767";
string resultString = String.Join("-", str.Split(new string[] { "^" }, StringSplitOptions.RemoveEmptyEntries));

So you can join like this.

所以你可以这样加入。

回答by john

string merge = String.Concat(stringArray);

字符串合并 = String.Concat(stringArray);