Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inserting formatting characters in String.Format?

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?

like image 566
Gulbahar Avatar asked Aug 13 '11 23:08

Gulbahar


Video Answer


1 Answers

"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))
like image 164
LarsTech Avatar answered Sep 30 '22 16:09

LarsTech