众所周知,string字符串去除空格的方法有trim()和replace(),区别在于trim()去首尾的空格,但是不能去中间的,而replace可以去除所有的空格. string data1=" a b c "; data1=data1.trim(); 结果为"a b c". string data1="a b c "; data1=data1.Replace(" ", "") 结果为“abc”.…
字符串拼接 直接用+号:String a = "I"; String b = "love"; String c = "you";String d = a+b+c;就能得到I love you了 "I"+"love"+"you"得到的也是I love you 字符串比较 ==和equals都能比较字符串,返回的都是boolean类型 String a ="I";Stri…
1.正则去空格 a.去掉字符串中所有空格 " hello world ".replace(/\s+/g,"");//helloworld b.去掉字符串左边空格 var str = " hello world ".replace(/^\s*/g,"");//hello world.. c.去掉字符串右边空格 var str = " hello world ".replace(/\s*$/g,"&q…
<script> var str=" ab cd "; alert("["+str.trim()+"]"); </script> 去掉后面空格 <script> //实现去掉字符串的右空格 String.prototype.rtrim=function(){ return this.replace(/\s+$/ig,""); } ; //声明一个js字符串,方便测试去空格功能 var str…