473,513 Members | 2,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 13457
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
12593
by: GlennH | last post by:
I am having trouble removing a pipe character using Regex.Replace - see the 2 NUnit tests below: The first replace works fine and the second Replace does not work. I've tried escaping the pipe...
6
8817
by: Chris Anderson | last post by:
Anyone know of a fix (ideally) or an easy workaround to the problem of escape characters not working in regex replacement text? They just come out as literal text For example, you'd think that thi...
4
3831
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said,...
3
8233
by: Craig Buchanan | last post by:
Is there a way to combine these two Replace into a single line? Regex.Replace(Subject, "\&", "&amp;") Regex.Replace(Subject, "\'", "&apos;") Perhaps Regex.Replace(Subject, "{\&|\'}", "{&amp;|&apos;}")...
9
4236
by: Whitless | last post by:
Okay I am ready to pull what little hair I have left out. I pass the function below my String to search, my find string (a regular expression) and my replace string (another regular expression)....
4
3137
by: Morgan Cheng | last post by:
In my case, I have to remove any line containing "0.000000" from input string. In below case, it takes about 100 ms for 2k size input string. Regex.Replace(inputString, ".*0\\.000000.*\n", ""); I...
15
50147
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
2
1812
by: Smokey Grindel | last post by:
I have an app that builds where clauses (its 3rd party) and for some reason it adds an m after decimal numbers... so I get results like this = 45.1234m And Like '123%' And = '45.1234m' ...
2
10632
by: Smokey Grindel | last post by:
I basically need to remove any leading zeros and hyphens from a string... regex seemed like the best rout and using a replace regex method... anyone know of any good strings for this? The one I...
0
7259
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7158
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7380
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5085
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3232
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
455
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.