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
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.
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.