for the below posted string, i want to replace any occurances of ,
with ,
i mean that the resultant string should contains values separated only by comma not a comma plus space.
the result of the below posted code is:
POLYGON((595117.1423555185 5784603.23154566,595123.4425648759 5784792.817361793, 595123.4467946623 5784792.959964871, 595131.3773480996 5785096.90776269, 595137.0802208507 5785261.194424775, 595196.9548982648 5785262.269346152, 595198.8303912097 5785262.391339741))
as shown in the latter string, the comma plus a space was removed only in the first occurance in
595117.1423555185 5784603.23154566,595123.4425648759 5784792.817361793
but for the further occurances of a comma plus a space, they did not changed at all
please let me know how to replace all occurances of ,
with ,
code:
let t = 'POLYGON((595117.1423555185 5784603.23154566, 595123.4425648759 5784792.817361793, 595123.4467946623 5784792.959964871, 595131.3773480996 5785096.90776269, 595137.0802208507 5785261.194424775, 595196.9548982648 5785262.269346152, 595198.8303912097 5785262.391339741))'
t=t.replace(', ',',')
console.log(t)
3
Answers
.replace will always replace just 1
you can use .replaceAll instead
Here is a link for it replaceAll MDN
Use
t=t.replaceAll(', ',',');
for replacing all ", " with ",".I feel like a simple google search would have come up with
String.prototype.replaceAll()
MDN.