Reputation: 23
I want to replace html entity
with a comma.
Html string : 2 077 Ft
//existing script - not working - adding comma after every second character
txt = txt.replace(/(\d{2})/g,"$1,")
I want an out put like
txt = 2,077 Ft
Upvotes: 0
Views: 1242
Reputation: 1520
Have you tried using string.replace(" ", ",");
?
Edit:as pointed out in the comments it only does the first instance. To get over this you need to use regex.
e.g.: string.replace(/ /g, ",");
Upvotes: 0
Reputation: 3998
var string = '2 077 Ft';
string = string.replace(/ /g, ',');
var modifiedElem = document.getElementById('modified');
modified.innerHTML = string;
<div id="original">2 077 Ft</div>
<div id="modified"></div>
This will replace all occurances of ' ' in desired string.
Upvotes: 3