Click to See Complete Forum and Search --> : Problem with string assignment escape character


vcdebugger
May 8th, 2009, 06:48 AM
Hi,

I am getting a escape character error when i assign a string to a text box with a '\' character

eg:

this.txtHeaderDirectory.Text = "C:\Temp";

so later i added excape character ' but still it is not working.. it is displaying C:''temp.. I want C:\Temp to be displayed.. how to do ?

thanks,

jmedved
May 8th, 2009, 07:15 AM
Use @:
this.txtHeaderDirectory.Text = @"C:\Temp";

Do notice that string will be saved as is (with one backspace), but it will be shown as two backspaces during debugging. This is quite normal.

MadHatter
May 8th, 2009, 07:33 AM
this.txtHeaderDirectory.Text = "C:\\Temp"; // escape the backslash if you don't use the verbatim identifier (above)

vcdebugger
May 10th, 2009, 11:51 PM
thanks it working fine now...

cilu
May 12th, 2009, 01:31 AM
Fore more you can take a look here: http://msdn.microsoft.com/en-us/library/aa691090.aspx.