Results 1 to 3 of 3

Thread: string function replace help

  1. #1
    Join Date
    Dec 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default string function replace help

    Hi I'm trying to replace commas in a string with spaces, it works for the first instance of a commas. but I dont know how to remove the rest:

    Code:
    var aString = "Humpty,Dumpty,sat,on,a,wall";
    document.write(aString.replace(","," "));

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    var aString = "Humpty,Dumpty,sat,on,a,wall";
    document.write(aString.replace(/,/g, ' '));
    The g means 'global'
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Dec 2005
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you very much

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
  •