javascript : trim white space

// trim blank space at the string
function trim_string( string ) {
   return string.replace(/(^\s*)|(\s*$)/g, '');
}

// trim blank space at the beginning
function left_trim_string( string ) {
   return string.replace(/(^\s*)/g, '');
}

// trim blank space at the end
function right_trim_string( string ) {
   return string.replace(/(\s*$)/g, '');
} 

0 comments:

Post a Comment