Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Double escape sequence 1

Status
Not open for further replies.

Dachyon

Programmer
Nov 4, 2002
32
NZ
Hi Experts,
I have a requirement to pass strings containing file paths from my .Net app to a MySQL database.
eg.
C:\Test\File.txt

In .Net the string value is displayed as "C:\\Test\\File.txt" in the debugger, however, when I commit that data to MySQL it gets written as "C:\Test\File.txt". Unfortunately MySQL also needs to escape the backslash character, so the resulting data ends up as "C:TestFile.txt"

I would like to programmatically replace "\\" with "\\\\" so that when .Net parses the string, MySQL receives "\\".

I have tried the following code
Code:
String s = "C:\\Test\\File.txt";
s.Replace("\\","\\\\");

However, it simply leaves the string unchanged. Nevertheless, it works if I type the string "C:\\\\Test\\\\File.txt" into a textbox.

Can anyone help me ?

Many Thanks.

 
Oh god, am I that obtuse ?
I had a feeling I was missing something obvious.
Thanks for pointing it out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top