How do you ignore escape sequences in a variable?

G

Guest

I am building a string from a combination of hardcoded string literals and user input (via textbox). I know about using @"c:\temp\filename.txt" to ignore escape sequences. Now let's say I have a string variable (to hold file path information) that is populated from a textbox. When I view the contents of the variable, while debugging, it shows @"c:\temp\filename.txt". But, when I concatenate it with other string literals or variables using the + operator, or even using a StringBuilder, the path info shown in the final output will be escaped. How can I tell C# to ignore the escape sequence already contained within a variable

Thanks in advance
Don
 
C

C# Learner

Don said:
I am building a string from a combination of hardcoded string literals and user input (via textbox). I know about using @"c:\temp\filename.txt" to ignore escape sequences. Now let's say I have a string variable (to hold file path information) that is populated from a textbox. When I view the contents of the variable, while debugging, it shows @"c:\temp\filename.txt". But, when I concatenate it with other string literals or variables using the + operator, or even using a StringBuilder, the path info shown in the final output will be escaped. How can I tell C# to ignore the escape sequence already contained within a variable?

I'm not quite sure I understand, since escape sequences *only* work in
string/character *literals* (values you specify in the source code).

For example, let's say I read a string from a file. After reading,
this string now contains "c:\test". No escape will happen here,
since I didn't actually write "c:\test" in the editor.

On the other hand if I were to use the following code, an escape will
happen:

string s = "c:\test";

Of course, as I'm sure you already know, preceding the string literal
with @, or using "\\" instead of '\', will prevent this.
 
G

Guest

False alarm. I was viewing contents of variables in Visual Studio to check that I was building the string correctly. Visual Studio will show string values in the help bubbles (by hovering mouse over code), and the Locals, Autos, and Command windows with escape sequences in place of characters that can be interperated as regular expression language operators. When I finally wrote these string values to the console, the escape sequences seen in the debugger were not there. Lesson learned. Thanks, anyway, for the reply.

Don
 
A

Ariel Gimenez

Hi everyone, just to know that... an activex control runs as inproc of the
executable or inproc?

thanks in advance

Don said:
I am building a string from a combination of hardcoded string literals and
user input (via textbox). I know about using @"c:\temp\filename.txt" to
ignore escape sequences. Now let's say I have a string variable (to hold
file path information) that is populated from a textbox. When I view the
contents of the variable, while debugging, it shows @"c:\temp\filename.txt".
But, when I concatenate it with other string literals or variables using the
+ operator, or even using a StringBuilder, the path info shown in the final
output will be escaped. How can I tell C# to ignore the escape sequence
already contained within a variable?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top