zoukankan      html  css  js  c++  java
  • javascript 取掉空格自定义函数

    js  取掉空格自定义函数

     1 //取掉左右空格:
     2 
     3 function trim(str){
     4 
     5    return str.replace(/(^s*)|(s*$)/g, "");   
     6 
     7 }
     8 
     9 //取掉左边空格:
    10 
    11 function ltrim(str){
    12 
    13  return str.replace(/(^s*)/g,"");  
    14 
    15 }
    16 
    17 //取掉右边空格:
    18 
    19 function rtrim(str){
    20 
    21    return str.replace(/(s*$)/g,"");  
    22 
    23 }
    24 
    25 //取掉所有空格:
    26 
    27 function trimAll(str){
    28 
    29 return str.replace(/s/g, "");
    30 
    31 //return str.replace(/s+/g, "");//两个都可以,如何第一个不可用,可使用第二个
    32 
    33 }
    34 
    35 //替换所有空格:
    36 
    37 function replaceAll(str){
    38 
    39   return str.replace(/[ ]/g, "-");//-:是指要把空格替换的字符
    40 
    41 }
  • 相关阅读:
    c++之类模板
    c++之函数模板
    c++之继承三
    c++之继承二
    c++之继承一
    c++之类类型转换
    c++之运算符重载二
    c++之运算符重载一
    Mahout学习路线路
    数据库分区
  • 原文地址:https://www.cnblogs.com/zlp520/p/4721174.html
Copyright © 2011-2022 走看看