字符串如下
aa bb cc dd ee fff
要求返回 aa bb cc dd ee fff
把字符串里多个连续空格替换为一个空格
------解决方案--------------------
- JScript code
var str = 'aa bb cc dd ee fff'; str = str.replace(/\s+/g, ' ');
------解决方案--------------------
- HTML code
<!DOCTYPE HTML> <html> <head> <meta charset="gb2312" /> <title></title> </head> <body> <script> var s = 'a b c d e f g'; var r = /\s+/g; s = s.replace(r, ' '); alert(s) </script> </body> </html>
------解决方案--------------------
- JScript code
var s = 'a b c d e f g'; while(s contians ' ') { s = s.replace(' ',' '); } alert(s)