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 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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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. ...
|
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...
|
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....
|
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...
|
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...
|
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...
|
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$) {
}
...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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,...
| |