开发者

Javascript replace a character with a space

I need to get the name of the p开发者_高级运维age 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'

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,' ');

Will replace any occurences of - with in the string string.


You would use String's replace method:

statelookup = statelookup.replace(/-/g, ' ');

API Reference here.


statelookup = statelookup.replace('-', ' ')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜