Trim处理-两侧(javascript)

来源:互联网 发布:怎么打开windows更新 编辑:程序博客网 时间:2024/04/30 01:41
function gfTrim(strValue) {
 var intLen = strValue.length;
 var intCnt;
 for (intCnt = 0; intCnt < intLen; intCnt++) {
  if (strValue.indexOf(' ') == 0) {//全角空格
   strValue=strValue.substring(1, intLen);
  }else if (strValue.indexOf(' ') == 0) {//半角空格
   strValue=strValue.substring(1, intLen);
  }else if (strValue.indexOf(' ') == 0) { //TAB
   strValue = strValue.substring(1, intLen);
  }else {
   break;
  }
 }
 intLen = strValue.length;
 for (intCnt = intLen; intCnt > 0; intCnt--) {
  if (strValue.lastIndexOf(' ') == intCnt - 1 ) {//全角空格
   strValue = strValue.substring(0, intCnt - 1 );
  }else if (strValue.lastIndexOf(' ') == intCnt - 1) {//半角空格
   strValue = strValue.substring(0, intCnt - 1 );
  }else if (strValue.lastIndexOf(' ') == intCnt - 1) { //TAB
   strValue = strValue.substring(0, intCnt - 1 );
  }else {
   break;
  }
  intLen = strValue.length;
 }
 return strValue;
}