remove '?' from a string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anudu
    New Member
    • Oct 2007
    • 31

    remove '?' from a string

    I have a string value in a javascript function , as ' var a=abcd?' . I want to remove the '?' char which is at the end of the string. I tried with a.replace(/?/g,''); but it gives a error when loading the page. how can i do this.
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    you have to escape the question mark since it is a quantifier for the regExp and you need it to be treated as a character:

    [CODE=javascript]a.replace(/\?/g,'')[/CODE]
    kind regards

    Comment

    • anudu
      New Member
      • Oct 2007
      • 31

      #3
      thanks. it works perfectly.

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        :) no problem ... post back to the forum anytime you have more questions ...

        kind regards

        Comment

        Working...