如何从字符串中删除文本? [英] How to remove text from a string?
本文介绍了如何从字符串中删除文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个data-123
字符串.
如何在离开123
的同时从字符串中删除data-
?
解决方案
var ret = "data-123".replace('data-','');
console.log(ret); //prints: 123
文档. >
要丢弃所有出现的事件,请使用:
var ret = "data-123".replace(/data-/g,'');
PS:replace函数返回一个新字符串,并使原始字符串保持不变,因此请在replace()调用之后使用该函数的返回值.
I've got a data-123
string.
How can I remove data-
from the string while leaving the 123
?
解决方案
var ret = "data-123".replace('data-','');
console.log(ret); //prints: 123
For all occurrences to be discarded use:
var ret = "data-123".replace(/data-/g,'');
PS: The replace function returns a new string and leaves the original string unchanged, so use the function return value after the replace() call.
这篇关于如何从字符串中删除文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文