[英]How to get remaining string after substring deletion in JavaScript?
I have a string 123456789
. 我有一个字符串123456789
。
My aim is to get 1236789
after deleting 45
. 我的目标是删除45
后得到1236789
。 I used slice method to delete the string 45
. 我使用了slice方法来删除字符串45
。
var x = 123456789;
res = x.slice(4, 5); //my output is 45
I need the output to be 1236789
我需要的输出是1236789
Any help would be appreciated. 任何帮助,将不胜感激。
try replace/2
. 尝试replace/2
。
"123456789".replace("45", "") /** 1236789 */
Or, if your input is an integer and you need and integer as an outcome, 或者,如果您输入的是整数,并且需要以整数作为结果,
var a = 123456789;
parseInt(a.toString().replace("45", ""))
You can so this: 您可以这样:
var x = "123456789"; var result = x.substr(0, 3) + x.substr(5); console.log(result)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.