StringBuilder的,值之间添加标签 [英] StringBuilder, add Tab between Values
本文介绍了StringBuilder的,值之间添加标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个小问题:
我有字段列表,具有3个值。我想建立我的字符串,这三个值,
通过一个分隔的TAB ..
I have a List of fields, with 3 Values. I want to build my String with these three Values, delimited by a "TAB"..
code:
StringBuilder stringBuilder = new StringBuilder();
foreach (string field in fields)
{
stringBuilder.Append(field).Append("\t");
}
stringBuilder.AppendLine();
return stringBuilder.ToString();
标签仅仅是第3和第2个数值之间(第一和第二之间是一个空间?!)
The Tab is only between the 3rd and 2nd Value (Between 1st and 2nd is a Space ?!)
所以,我想这样的:
StringBuilder stringBuilder = new StringBuilder();
foreach (string field in fields)
{
stringBuilder.Append(field + "\t").Append("\t");
}
stringBuilder.AppendLine();
return stringBuilder.ToString();
然后,我有第三和第二之间2标签,第一和第二,也是一个空间之间的一个标签
第一和第二之间的..
Then I have 2 Tabs between 3rd and 2nd, one Tab between 1st and 2nd and also a Space between 1st and 2nd..
(空间总是存在的,如何避免?)
(The Space is always there, how to avoid that?)
所以我有什么关系?需要的仅(无空格。)这些值之间的标签。
So what I have to do? Need only (without spaces..) a Tab between these Values..
推荐答案
尝试
StringBuilder stringBuilder = new StringBuilder();
foreach (string field in fields)
{
stringBuilder.Append(field.Trim()).Append("\t");
}
stringBuilder.AppendLine();
return stringBuilder.ToString();
基本上,我只想用 返回的string.join(\\ t的,域);
这篇关于StringBuilder的,值之间添加标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文