RegEx.Replace() to remove double-backslashes in a path

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

OpenFileDialog gives me the following, which I place in tbDevPath.Text:

x:\\myVob\\mySolution\\mySolution.sln

I really need this path to be single-backslashes, not double-backslashes, so
I tried the following:

string updatedDevPath = Regex.Replace(tbDevPath.Text, @"^\\\\$", "\\")

This still leaves me with double-backslashes. Any suggestions?

Thanks,
Randy
 
Uh, OpenFileDialog doesn't give you that path. Something is going
wrong with the way you're writing out your text or storing your text.
Using .NET 2.0?

Notwithstanding that, I'd try this:

string updatedDevPath = tbDevPath.Text.Replace(@"\\", @"\");

And then I'd do some research on the ^ and $ operator in a regex.
 
randy1200 said:
OpenFileDialog gives me the following, which I place in
tbDevPath.Text:

x:\\myVob\\mySolution\\mySolution.sln

I really need this path to be single-backslashes, not
double-backslashes, so I tried the following:

string updatedDevPath = Regex.Replace(tbDevPath.Text, @"^\\\\$", "\\")

This still leaves me with double-backslashes. Any suggestions?

Don't be misled by the debugger helping you out by showing the string
literal in the form you'd have to write it in code. The path from
OpenFileDialog most certainly doesn't contain double backslashes.

-cd
 
randy1200 said:
OpenFileDialog gives me the following, which I place in tbDevPath.Text:

x:\\myVob\\mySolution\\mySolution.sln


Obligatory movie reference!
Boy: Do not try to bend the double-backslashes; that's impossible.
Instead, only try to realize the truth.
Neo: What truth?
Boy: There are no double-backslashes.
Neo: There are no double-backslashes?
Boy: Then you will see, it is not the double-backslashes that bend, it is
only yourself.
http://en.wikiquote.org/wiki/The_Matrix
I really need this path to be single-backslashes, not double-backslashes,
so
I tried the following:

string updatedDevPath = Regex.Replace(tbDevPath.Text, @"^\\\\$", "\\")

This still leaves me with double-backslashes. Any suggestions?


Try looking at tbDevPath.ToCharArray() in the debugger instead of the string
itself.
 
Back
Top