字符串截取

看到一道前端的面试题 

对string对象经行扩展,使其具有删除前后空格的方法;
 
 1 <script type="text/javascript">
 2     String.prototype.delempty = function(){
 3         var str = this;
 4         while(str[0] == " ")
 5         {
 6             str = str.substring(1);
 7         }
 8 
 9         while(str[str.length-1] == " ")
10         {
11             str = str.substring(0,str.length-1);
12         }
13         return str;
14 
15     }
16 </script>

 

posted @ 2014-03-07 23:33  likelight  阅读(139)  评论(0编辑  收藏  举报