---
title: "js getTextLen,trim"
author: "zhuguo_guo"
date: "2012-01-02T16:26:27Z"
tags: []
categories: ["Web前端"]
slug: "js-gettextlen-trim"
draft: false
lastmod: "2012-01-02T16:31:22Z"
id: 1333207
url: "https://zhuguo.iteye.com/blog/1333207"
---

function getTextLen(s) 					
    {
    	var newlength=0;
	for(i=0;i<s.length;i++)			
         {							    var chrInput;
       	    chrInput=escape(s.charAt(i));
      	    if(chrInput.length==6) 
                  {newlength=newlength+3;}
       	    else {newlength=newlength+1;}				}
         return newlength;
     }							

     function trim(s) 
     {
        var tempStr;
        tempStr = s.replace(/\s+$/g,'');
        tempStr = tempStr.replace(/^\s+/g,'');
        return tempStr;					
      }