JavaScriptで文字列の前後の空白を取り除く方法
//左の空白;
function ltrim(s){
return s.replace(/^(\s*|*)/,"");
}
//右の空白;
function rtrim(s){
return s.replace(/(\s*|*)$/,"");
}
//左右の空白;
function trim(s){
return ltrim(rtrim(s));
}
Coding Changes the World
//左の空白;
function ltrim(s){
return s.replace(/^(\s*|*)/,"");
}
//右の空白;
function rtrim(s){
return s.replace(/(\s*|*)$/,"");
}
//左右の空白;
function trim(s){
return ltrim(rtrim(s));
}