By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,562 Members | 1,298 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,562 IT Pros & Developers. It's quick & easy.

How do you ignore escape sequences in a variable?

P: n/a
Don
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
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Don <an*******@discussions.microsoft.com> wrote:
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.
Thanks in advance,
Don


Nov 15 '05 #2

P: n/a
Don
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
Nov 15 '05 #3

P: n/a
Hi everyone, just to know that... an activex control runs as inproc of the
executable or inproc?

thanks in advance

"Don" <an*******@discussions.microsoft.com> wrote in message
news:84**********************************@microsof t.com...
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

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.