473,387 Members | 1,492 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,387 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 17423
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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.