By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,564 Members | 834 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,564 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
May 7 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

May 7 '07 #2

P: n/a
randy1200 wrote:
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
May 7 '07 #3

P: n/a

"randy1200" <ra*******@discussions.microsoft.comwrote in message
news:52**********************************@microsof t.com...
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.

>
Thanks,
Randy

May 8 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.