Javascript用空格替换字符 [英] Javascript replace a character with a space
本文介绍了Javascript用空格替换字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从网址获取网页的名称。我这样做了:
I need to get the name of the page from a url. I did this way:
var filename = window.location.href.substr(window.location.href.lastIndexOf('/')+1)
// -> 'state.aspx'
var statelookup = filename.substr(0, filename.lastIndexOf('.'))
// -> 'state'
现在我的statelookup有一个像New-York或North-Carolina的值,如何用中间的空格替换连字符?
Now for e.g, my statelookup has a value like New-York or North-Carolina, how do I replace hyphen with a space in between?
推荐答案
string.replace(/ - / g ,'');
将用<$ c替换 -
的任何出现字符串字符串
中的$ c> 。
Will replace any occurences of -
with in the string
string
.
这篇关于Javascript用空格替换字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文