468,738 Members | 2,655 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,738 developers. It's quick & easy.

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

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
3 12887
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
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

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

Similar topics

1 post views Thread by GlennH | last post: by
9 posts views Thread by Whitless | last post: by
4 posts views Thread by Morgan Cheng | last post: by
15 posts views Thread by morleyc | last post: by
2 posts views Thread by Smokey Grindel | last post: by
2 posts views Thread by Smokey Grindel | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.