当前位置:网站首页>js去除字符串空格
js去除字符串空格
2022-06-24 12:59:00 【莉兹Liz】
js原生方法trim()
str = str.trim();
局限:只能去除字符串两边空格
let str = " 1 2 3 ";
str0 = str.trim();
// "1 2 3"
正则表达式
去除字符串所有空格
str = str.replace(/\s*/g,"");
去除字符串两边空格
str = str.replace(/^\s*|\s*$/g,"");
去除字符串左侧空格
str = str.replace(/^\s*/g,"");
去除字符串右侧空格
str = str.replace(/\s*$/g,"");
str1 = str.replace(/\s*/g,"");
// "123"
str2 = str.replace(/^\s*|\s*$/g,"");
// "1 2 3"
str3 = str.replace(/^\s*/g,"");
// "1 2 3 "
str4 = str.replace(/\s*$/g,"");
// " 1 2 3"
参考
边栏推荐
- Rasa 3.x 学习系列-非常荣幸成为 Rasa contributors 源码贡献者,和全世界的Rasa源码贡献者共建共享Rasa社区!
- Docker安装redis
- 一个团队可以既做项目又做产品吗?
- 2022 construction elevator driver (construction special type of work) examination questions and online simulation examination
- Explain kubernetes backup and recovery tools velero | learn more about carina series phase III
- Gatling 性能测试
- Simulated 100 questions and answers of fluorination process examination in 2022
- What is the difference between sap QM and UD for inspection lots with hum?
- 图扑软件数字孪生海上风电 | 向海图强,奋楫争先
- 90%的项目经理都跳过的坑,你现在还在坑里吗?
猜你喜欢

Seven challenges faced by data scientists and Solutions

Cloud native essay solicitation progress case practice

《中国数据库安全能力市场洞察,2022》报告研究正式启动

Tupu software is the digital twin of offshore wind power, striving to be the first

Dragon lizard developer said: first time you got an electric shock, so you are such a dragon lizard community| Issue 8

谷歌WayMo提出R4D: 采用参考目标做远程距离估计

HarmonyOS-3

These default routes and static routes can not be configured and deployed. What kind of network workers are they!

npm包【详解】(内含npm包的开发、发布、安装、更新、搜索、卸载、查看、版本号更新规则、package.json详解等)

居家办公更要高效-自动化办公完美提升摸鱼时间 | 社区征文
随机推荐
一个团队可以既做项目又做产品吗?
The hidden corner of codefarming: five things that developers hate most
返回新列表
Promotion of Project Manager
kotlin 语言特性
Kotlin language features
杰理之.睡眠以后定时唤醒系统继续跑不复位【篇】
The real project managers are all closed-loop masters!
Detailed explanation of kotlin collaboration lanch
kotlin 接口 泛型 协变 逆变
【sdx62】WCN685X IPA不生效问题分析及解决方案
首席信息安全官仍然会犯的漏洞管理错误
华为 PC 逆势增长,产品力决定一切
Tupu software is the digital twin of offshore wind power, striving to be the first
2022年质量员-设备方向-岗位技能(质量员)复训题库及在线模拟考试
Home office should be more efficient - automated office perfectly improves fishing time | community essay solicitation
HarmonyOS-3
#21Set经典案例
PM should also learn to reflect every day
90%的项目经理都跳过的坑,你现在还在坑里吗?