Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

How can u add two backslashes to a string?


  • Please log in to reply

#1
HappyTomato

HappyTomato

    Member

  • Member
  • PipPip
  • 38 posts
hi, I've got this C# problem that i cant solve.. could someone please give me a hand on this? :tazz:

i'm having trouble putting two backslashes in a string, here's what I was trying to do.. I needed to replace the single backslash in a file path with two backslashes, I have written a little method to do something similar already. for example:

string filelocation = Regex.Replace(prelocation,"\"","");

will replace all double quotes in the string with nothing (in another word it takes out the double quotes) and i know this works

however, with backslashes, it doesn't apear to work...for example

string filelocation = Regex.Replace(prelocation,"\\","\\\\");

doesnt work. the program stop with an error that says
"Additional information: parsing "\" - Illegal \ at end of pattern."

I've also even tried

string filelocation = Regex.Replace(prelocation,@"\",@"\\");

which also gives the same error


any help is appreciated!! ;)
  • 0

Advertisements


#2
HappyTomato

HappyTomato

    Member

  • Topic Starter
  • Member
  • PipPip
  • 38 posts
it worked! :tazz:
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP