javascript - Replace nth word in sentence -
i have function string, i'm looking way format 3rd word (which number, want format comma). idea how it? should that:
function formatnumber(txt){ return txt.replace(3rd-word, formatnumber(3rd-word)); }
match word consists of digits, , format it:
txt = txt.replace(/\b(\d+)\b/g, format);
using formatting function, example:
function format(s) { var r = ''; while (s.length > 3) { r = ',' + s.substr(s.length - 3) + r; s = s.substr(0, s.length - 3); } return s + r; }
Comments
Post a Comment