replace occurance of a character in a string

Discussion in 'JavaScript' started by zurc, Mar 26, 2007.

  1. #1
    Hi can anyone help me replace a specific character that occur in a string with another character regardless how many characters to replace
     
    zurc, Mar 26, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Can you maybe post an example of what you want to replace?
     
    nico_swd, Mar 26, 2007 IP
  3. SeLfkiLL

    SeLfkiLL Active Member

    Messages:
    85
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    50
    #3
    Use this for a global text replace:
    your_str.replace(/old_char/g, 'new_char');
    Code (markup):
    or this for global case-insensitive text replace:
    your_str.replace(/old_char/gi, 'new_char');
    Code (markup):
     
    SeLfkiLL, Mar 26, 2007 IP