473,287 Members | 1,643 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

How do you ignore escape sequences in a variable?

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
3 17382
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JehanNYNJ | last post by:
I have to put some html into a variable like so.... var html = '<TABLE cellspacing="5" border="0" ....... But within this html string I also need to have the code for a button that traps the...
6
by: Walter L. Preuninger II | last post by:
I need to convert escape sequences entered into my program to the actual code. For example, \r becomes 0x0d I have looked over the FAQ, and searched the web, with no results. Is there a...
18
by: Steve Litvack | last post by:
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1...
3
by: Ken | last post by:
HI: I'm reading a string that will be displayed in a MessageBox from a resource file. The string in the resource file contains escape sequences so they will be broken up into multiple lines. ...
5
by: nummertolv | last post by:
Hi, My application is receiving strings, representing windows paths, from an external source. When using these paths, by for instance printing them using str() (print path), the backslashes are...
15
by: pkaeowic | last post by:
I am having a problem with the "escape" character \e. This code is in my Windows form KeyPress event. The compiler gives me "unrecognized escape sequence" even though this is documented in MSDN....
4
by: JJ | last post by:
Is there a way of checking that a line with escape sequences in it, has no strings in it (apart from the escape sequences)? i.e. a line with \n\t\t\t\t\t\t\t\r\n would have no string in it a...
10
by: hanaa | last post by:
Hello there. $str="This is \na ball"; echo $str; Is there a way i can make the text to be as is, without expanding the escape sequences. I know that single quoted strings do not expand escape...
5
by: John Ztwin | last post by:
Hello, I have a file that contains ordinary text and some special charaters in Unicode escape sequences (\uxxxx). When I read the file using e.g. StreamReader Unicode escape sequences are not...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.