字符串处理

Posted sweetyu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了字符串处理相关的知识,希望对你有一定的参考价值。

replace

str.replace(/<\/?[^>]*>/g,‘‘); //去除html tag

str.replace(/[ | ]*\n/g,‘\n‘); //去除行尾空白

str.replace(/\n[\s| | ]*\r/g,‘\n‘); //去除多余空行

str.replace(/ /ig,‘‘);//去掉

str.replace(/^[\s ]+|[\s ]+$/g, "");//去掉全角半角空格

str.replace(/[\r\n]/g,"");//去掉回车换行

str.replace(/(^/s*)|(/s*$)/g, ""); // 去掉左右空格

str.replace(/(^/s*)/g, ""); // 去掉左空格

str.replace(/(/s*$)/g, ""); // 去掉右空格

join

arr=["1","1","1","1"];

str=arr.join(",");    //str=1,1,1,1

split

str="1,1,1,1";

arr=str.split(",");    //["1","1","1","1"];

 

以上是关于字符串处理的主要内容,如果未能解决你的问题,请参考以下文章