Search This Blog

Javascript trim


function trim(str){
    return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}


function trim (str) {
    var    str = str.replace(/^\s\s*/, ''),
        ws = /\s/,
        i = str.length;
    while (ws.test(str.charAt(--i)));
    return str.slice(0, i + 1);
}

No comments:

Post a Comment