I am using folderdialogbox in one of my application. When a directory is selected and assigned to another string, I get a value like C:\\test
For some of the assignments, I would like the value of c:\test.
I researched on stackoverflow, but did not find any working answer. I tried all kind of replacement, but it does not work.
Any help will be greatly appreciated.
The Codes:
private void label1_Click(object sender, EventArgs e)
{
folderBrowserDialog1.ShowNewFolderButton = false;
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
string p = @folderBrowserDialog1.SelectedPath; //=> Selected C:\ACTNT
//removing @ in front of folderBrowserDialog1 does not change the situation
strPathName.Text = p; // => display c:\ACNT
con = "database = " + p; // => actual value "database = c:\\ACNT"
UpdateTableName();
}
}
If I type manually in strPathName as C:\ACNT , the program runs fine.
The other answers so far are talking about assigning string literals, but it sounds like you’re getting this string via a GUI anyway, in which case that’s irrelevant.
What is relevant is how you’re determining that the string is actually
c:\\test. I strongly suspect you’re looking at it in the debugger – which automatically applies C# escaping when it displays the string.If you just print it to the screen, or even example it character by character (e.g. call
ToCharArray()) I think you’ll find it only has a single backslash. Don’t be fooled by the debugger.