2011/03/10

js trim

how to trim a string using js?

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


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

str = trim(str);


jquery:
str = $.trim(str);


str =  str.strip();

沒有留言:

發佈留言