javascript去除字串前后的空格

  /** 去除字串前后的空格  */  
function trim(s) {  
  var count = s.length;  
  var st    = 0;       // start  
  var end   = count-1; // end  
  
  if (s == "") return s;  
  while (st < count) {  
    if (s.charAt(st) == " ")  
      st ++;  
    else  
      break;  
  }  
  while (end > st) {  
    if (s.charAt(end) == " ")  
      end --;  
    else  
      break;  
  }  
  return s.substring(st,end + 1);  
} 

抄自: http://blog.csdn.net/lutinghuan/article/details/8275800



你可能感兴趣的:(javascript去除字串前后的空格)