SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Replace every instance of character in string

    Hello all,
    I know I can use replace() to get rid of one instance of a character in a string. How do you get rid of EVERY instance of that character? Is there something like replaceAll()? (Yes, I know...I've tried it and it doesn't work)

    Mark

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just add "g" flag to the regular expression:
    Code:
    alert("foo".replace(/o/g, "x"))

  3. #3
    SitePoint Member
    Join Date
    Jul 2007
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks stereofrog! RIBBIT!


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
  •