从数字字符串中删除所有前导零 [英] Remove all leading zeros from numeric string
本文介绍了从数字字符串中删除所有前导零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下情况:
- 09189898989
- 00898989899
我想使用JavaScript从字符串中删除所有前导零
I want to remove all leading zeros from the string using JavaScript
什么是最好的方法完成这个?
What is the best way to accomplish this?
推荐答案
您可以使用正则表达式匹配字符串开头的零:
You can use a regular expression to match the zeroes at the beginning of the string:
str = str.replace(/^0+/, '');
这篇关于从数字字符串中删除所有前导零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文