What the hell isn't going on?

Discussion in 'JavaScript' started by Chri5ty, Feb 11, 2007.

  1. #1
    :confused: :eek: Who can tell me what's wrong???

    This was suposed to eliminate spaces at the beginind and at the end of a string.If there are two spaces they should be eliminated. But why the string "result" remains unchanged?:(

     
    Chri5ty, Feb 11, 2007 IP
  2. MattD

    MattD Peon

    Messages:
    161
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why not just use something like this?

    
    str = str.replace(/^\s*|\s*$/g,"");
    
    Code (markup):
    Not had a long look at your code but what I think you doing is are setting result to a single character each time, and not appending the string.
     
    MattD, Feb 11, 2007 IP
  3. Chri5ty

    Chri5ty Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks. But what is that shit?
    What shoud I do? Be more clearly.
     
    Chri5ty, Feb 11, 2007 IP
  4. MattEvers

    MattEvers Notable Member

    Messages:
    1,792
    Likes Received:
    137
    Best Answers:
    0
    Trophy Points:
    260
    #4
    MattEvers, Feb 11, 2007 IP
  5. Chri5ty

    Chri5ty Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    :mad: I'm getting crazy. I tryed everything.
    Everytime I get an empty string as a result.:mad: :mad: :mad:
     
    Chri5ty, Feb 11, 2007 IP
  6. MattD

    MattD Peon

    Messages:
    161
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    "That shit" is a regular expression that removes all excess spaces at the start and end of the str variable.
     
    MattD, Feb 11, 2007 IP