How to concatenate a backslash?
Hi all!
I have a condition that compare two strings n' I heve a problem to concatenate. I heve the below condition:
if (myFileInfo.DirectoryName + "\\" != MyPath)
The result of the condition must be true but it doesn't run the if statement. I've inserted a breakpoint in this line and the values are the next:
myFileInfo.DirectoryName = "C:\Program Files"
MyPath = "C:\Program Files\"
myFileInfo.DirectoryName + "\\" = "C:\Program Files\\"
The problem is the doble backslash. If I write only one (... + "\") an exception is thrown.
I tried with the verbatim symbol (... + @"\") n' in the breakpoint the values are the next:
myFileInfo.DirectoryName = "C:\Program Files"
MyPath = "C:\Program Files\"
myFileInfo.DirectoryName + @"\" = error: maneged EE does not understand the expression's syntax
Any idea? Taking in mind that I have others conditions n' if I modify Mypath string in the others condition I'd have the same problem)
Thanx in advance
Regards
Carlos SanchezPosted Oct 11, 2004, 5:29 PM
jsheplerPosted Oct 6, 2004, 3:03 PM
void test1() { string s1, s2, s3; s1 = @"C:\Program Files"; s2 = @"C:\Program Files\"; Response.Write("s1 = " + s1 + "and it worked just fine. On a whim, I made a console app that did:\ns2 = " + s2 + "
\ns1 + \\ = " + s1 + "\\" + "
\n"); if(s1 + "\\" == s2) Response.Write("true"); else Response.Write("false"); }
static void Main(string[] args) { string s1, s2; s1 = @"C:\Program Files"; s2 = @"C:\Program Files\"; Console.WriteLine("s1 = " + s1 + "\ns2 = " + s2 + "\ns1 + \\ = " + s1 + "\\"); if(s1 + "\\" == s2) Console.WriteLine("true"); else Console.WriteLine("false"); }and that worked fine as well. So.. I would suspect an errant character (typo) or something else in your code that has nothing to do with the double backslash.Carlos SanchezPosted Oct 1, 2004, 1:33 PM