views:

506

answers:

4

Hi How do i add a TAB (\t) to a string resource ?

"\tText" doesn't work

+6  A: 

You have to explicitly add the tab in. The easiest way of doing this is probably to type out your string in notepad (with the tab explicitly set in place rather then using an escape character) and copy and paste the text into the resource editor.

You will have a similar problem with newlines, the easiest way of adding them in is to - again - add newlines in explicitly by using the shift-enter key combination.

jpoh
+1: Yep, pretty much the only logical way.
John Gietzen
Notepad - the programmers best friend!
Treb
i've tried copy pasting it doesn't workShift+tab worked for newline
Gady
Works for me in VS 2008 Professional and Express (C#)
jpoh
Tab works in the middle of the string, but not at the beginning
Gady
You're right. It seems like the resource editor is trimming white space or something. Not very helpful (in your case!)
jpoh
A: 

Have you tried the XML tab character?

Sorry my tab character didn't show! Must have got eaten up by the browser.

	
joshcomley
+3  A: 

You have two options that I am aware of:

1) Do a string replace after reading your resource string: s = s.Replace("\\t","\t");

2) Enter the escape sequence directly into your resource string at creation time by typing Alt-012 (I think that's tab) on the numeric keypad.

Articles on the same here and here.

Xiaofu
Option 1 is what I do.
Finglas
A: 

\t does add an ascii tab but if you are displaying this in an html page you will not see that tab except in the page source. HTML doesn't render tabs or new-lines as non-breaking space. They all get reduced to 1 space character when displayed. Formatting HTML with whitespace is not recommended, that is what div with CSS or even Table are for. If you must add extra white space in HTML use the   repeatedly but it will not be tab stop correct and will create a nightmare if you ever copy and paste.

Alternately you can display your string data in a read-only Text Area. This will preserve your string format. Without knowing the specifics of what you are trying to do with your string or how you are creating it these are the best suggestions I can give you.

You can also create a variable but the \t works inline.

string TAB = char.ConvertFromUtf32(9).ToString();
benjamin
I guess I misread the question, you are pulling the string in from an external resource file then yes, you have to either do the string replace or enter the escape sequence directly as Xiaofu stated.
benjamin