SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2001
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    String replacement

    I need to replace any apostraphies (') in a string with \' using javascript, anyone know how i can do that?
    Thanks
    Love Sythe
    xxx

  2. #2
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Sythe, you just need to use the replace method,
    Code:
    var st = "Paul's function";
    var d = document;
    
    d.write(st+"<br>");
    st = st.replace("'","\\ '");
    d.write(st+"<br>");
    Paul
    PS (Remove the space between the two slashes and the apostrophe, vB don't show them correct)

  3. #3
    SitePoint Guru
    Join Date
    Sep 1999
    Location
    Singapore
    Posts
    854
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to explore this further, search for "javascript regular expressions" on your favourite search engine.


Bookmarks

Posting Permissions

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