www.webdeveloper.com
Results 1 to 4 of 4

Thread: Replace Single Backslash with Double Backslash

  1. #1
    Join Date
    Aug 2010
    Posts
    33

    Replace Single Backslash with Double Backslash

    I have a need to replace single backslashes with double backslashes. I know that the replace method of the string object can be used, however I'm not able to figure out the correct combination given that the backslash serves as an escape character.

    \\[string]\[string]\[string]

    Needs to become

    \\\\[string]\\[string]\\[string]

  2. #2
    Join Date
    Jan 2011
    Location
    United Kingdom, London
    Posts
    117
    you need to use "\\" to display one, so for "\\" you need to use "\\\\"
    Javascript, jQuery / Prototype & PHP expert ready to complete your work on Freelancer.co.uk - Hire Me at https://www.freelancer.co.uk/users/1...&action=hireme

  3. #3
    Join Date
    Aug 2010
    Posts
    33
    I was doubling up on them, but not getting the results that I needed.

    ex: t.replace("\\","\\\\")

    Its now a moot point as I ran into some other issues that required a complete overall eliminating the need entirely.

  4. #4
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,266
    It seems to work better with a regular expression
    Code:
    var t="\\\\[string]\\[string]\\[string]";alert("Before "+t);
    var u=t.replace(/\\/g,"\\\\");alert("After "+u);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles