在格式化值之间的C#字符串具有相同的间距 [英] Formatting a C# string with identical spacing in between values

查看:193
本文介绍了在格式化值之间的C#字符串具有相同的间距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个字符串。第一组的字符串是:

I have 3 strings. The first set of strings are:

"1.0536"  
"2.1"  
"2" 

二是这样的:

"Round"  
"Square"  
"Hex"

和最后一个是:

"6061-T6"  
"T351"  
"ASF.3.4.5" 

我需要三个串在一起具有相同的间距在每个字符串之间的结合。我不能用\\ t表示Tab键后,如结合我的琴弦,我送他们到Access数据库。

I need to combine the three strings together with identical spacing in between each string. I can't use \t for tabbing as after I combine the strings, I send them to an Access Database.

当我结合他们看起来像琴弦:

When I combine the strings they look like:

"1.0536 Round 6061-T6"  
"2.1 Square T351"  
"2 Hex ASF.3.4.5" 

我真的很想他们看起来像这样与间距相同的确切数额在每个字符串之间:

I would really like them to look like this with the same exact amount of spacing in between each string:

1.0536     &轮NBSP;     6061-T6结果
\"2.1           Square    T351\"

\"2              Hex          ASF.3.4.5\"

"1.0536     Round     6061-T6"
"2.1           Square    T351"
"2              Hex          ASF.3.4.5"

我怎么能做到这一点的C#?

How can I do this with C#?

推荐答案

您可以使用先进的功能 的String.Format

You can use advanced features of string.Format:

string.Format("{0,-10}{1,-10}{2}", ...)

您可以通过写做同样的事情 str.PadRight(10)

You can do the same thing by writing str.PadRight(10)

这篇关于在格式化值之间的C#字符串具有相同的间距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆