Insert formatting characters into String.Format?

I searched this for Google, but VB.Net (2008) does not seem to allow formatting characters (e.g. \ t, \ r \ n) to be inserted into 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 create a formatted string that should contain formatting characters?

+4
source share
3 answers

Lighter, probably in the eye of the beholder, but here's another way:

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

I also came up with the following:

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

Using vbTab works great (and vbCrLf etc.).

\ t \ n etc. is fior C, not VB

{tab} is the code for SendKeys

I conclude that your 3rd line is a (only) working method, if only something like this

MessageBox.Show("Foo" & vbTab & "Bar")

perhaps: it is easier to read, I think.

+2
source

I suggest another option:

 String.Format("{1}{0}{2}{0}{3}{0}{4}", vbTab, "Foo", "Bar", "was", "here") 

Not the most readable, but better than & vbTab & .

+2
source

All Articles