在String.Format中插入格式化字符? [英] Inserting formatting characters in String.Format?

查看:220
本文介绍了在String.Format中插入格式化字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google搜索,但VB.Net(2008)似乎不允许在String.Format中插入格式化字符(例如\ t,\r\\\
):

 'BAD MessageBox.Show(String.Format({0} {tab} {1},Foo,Bar))
'MessageBox.Show(String.Format({0} \ {1},Foo,Bar))
MessageBox.Show(String.Format({0} & vbTab&{1},Foo,Bar))

有一个更简单的方法来建立一个格式化的字符串,必须包含格式化字符?

解决方案

更容易但是这里有一个不同的方法:
$ b $ pre $ MessageBox.Show(String.Join(vbTab,{Foo,Bar }))

我也想出了这个:

  MessageBox.Show(String.Format({0} \ {1} \t {2},Foo,Bar,Test ).Replace(\t,vbTab))


I googled for this, but VB.Net (2008) doesn't seem to allow inserting formatting characters (eg. \t, \r\n) in String.Format:

'BAD MessageBox.Show(String.Format("{0}{tab}{1}", "Foo", "Bar"))
'BAD MessageBox.Show(String.Format("{0}\t{1}", "Foo", "Bar"))
MessageBox.Show(String.Format("{0}" & vbTab & "{1}", "Foo", "Bar"))

Is there an easier way to build a formatted string that must contain formatting characters?

解决方案

"Easier" is probably in the eye of the beholder, but here is a different way:

MessageBox.Show(String.Join(vbTab, {"Foo", "Bar"}))

I also came up with this:

MessageBox.Show(String.Format("{0}\t{1}\t{2}", "Foo", "Bar", "Test").Replace("\t", vbTab))

这篇关于在String.Format中插入格式化字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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