javascript在部分分割字符串 [英] javascript split string at parts
本文介绍了javascript在部分分割字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
javascript格式的数字
我有一个字符串代表一个数字: 3507654
我需要将它拆分为3,例如3 507 654
I have a string represents a number: "3507654" I need to split it on a parts, by 3, e.g "3 507 654"
数字可以是任何值,但总是数字。
Number can be any value, but always a number.
推荐答案
您可以执行以下操作:
"3507654".replace(/(\d)(?=(?:\d{3})+$)/g, "$1 ")
但这不是很有效,因为它是O(n 2 )。
But this is not very efficient since it’s O(n2).
这篇关于javascript在部分分割字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文