本文介绍了如何使用 JavaScript 替换字符串中的所有点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想替换 JavaScript 字符串中所有出现的点(.
)
I want to replace all the occurrences of a dot(.
) in a JavaScript string
例如,我有:
var mystring = 'okay.this.is.a.string';
我想得到:好的,这是一个字符串
.
到目前为止我尝试过:
mystring.replace(/./g,' ')
但这最终将所有字符串替换为空格.
but this ends up with all the string replaced to spaces.
推荐答案
你需要对 进行转义.
因为它在正则表达式中具有任意字符"的含义.
You need to escape the .
because it has the meaning of "an arbitrary character" in a regular expression.
mystring = mystring.replace(/./g,' ')
这篇关于如何使用 JavaScript 替换字符串中的所有点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!