Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
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