Removing return characters from a string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bugboy
    New Member
    • Sep 2007
    • 160

    Removing return characters from a string

    Hi, I need to remove the return characters from a string but i can't figure out how to reference it in a replace() method.

    Code:
    this.value=this.value.replace(/char(13)/, "");
    Also when i test the code by replacing the letter /a/ it only replaces the first instance of it.. how do i get it to replace them all?

    Thanks!
  • webster5u
    New Member
    • Jan 2008
    • 28

    #2
    try to put the global match into your RegEx.

    this.value.repl ace(/a*/g, "");

    Comment

    • bugboy
      New Member
      • Sep 2007
      • 160

      #3
      Thanks! as it turns out /a*/g can just be /a/g if you want to replace 'a' with a different character... otherwise it add the new char after every letter.

      this.value=this .value.replace(/a/g, "");

      Comment

      • bugboy
        New Member
        • Sep 2007
        • 160

        #4
        Also a 'return' is a 'new line' so it's accessed via \n

        this.value=this .value.replace(/\n/g, "");

        Comment

        • bugboy
          New Member
          • Sep 2007
          • 160

          #5
          Thanks for the help guys!

          Comment

          Working...