字符串连接问题 [英] String Concatenation Problem
本文介绍了字符串连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
连接两个字符串时遇到问题。可以解决任何问题吗?
I had a problem when concatenating two string..can any one figure it out?
List values = new List(){"This ","is ","Sparta ","!"};
string outputValue = string.Empty;
foreach (var value in values)
{
outputValue += value;
}
推荐答案
试试
List<string> values = new List<string>() { "This ", "is ", "Sparta ", "!" };
string outputValue = string.Empty;
foreach (var value in values)
{
outputValue += value;
}
您好b $ b
我找到了解决问题的方法。使用字符串生成器解决了这些问题
Hi
I found the solution for my issue. using string builder solves the probs
StringBuilder outputValueBuilder = new StringBuilder();
foreach (var value in values)
{
outputValueBuilder.Append(value);
}
ArrayList values = new ArrayList(){"This ","is ","Sparta ","!"};
string op = string.Empty;
op = string.Join("", values.ToArray());
这篇关于字符串连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文