0

I wanna replace "," by "." in the same row, so first this is my data:

36,760064   2,984077    Cabinet Dr Baba Ahmed
36,741802   3,038135    Pharmacie Boukhalfa
36,741799   3,038052    Cabinet Dr Baba Ahmed
36,669028   2,955786    Polyclinique de Beaulieu

And as result i wanna have this:

36.760064   2.984077    Cabinet Dr Baba Ahmed

and this is my code javascript:

for(var i = 0; i < data.length; i++) {

  var line = data[i].trim().replace(/\s\s+/g , '.').split(" ");
  line[0] = line[0].replace(",", ".");          

  output += ' <wpt lat="' + line[0] + '" lon="' + line[1] + '">\r\n';
  output += '  <name>' + line[2] + '</name>\r\n';
  output += ' </wpt>\r\n';
}

but as result i get only this:

<wpt lat="36.760064" lon="2,984077">
  <name>Cabinet Dr Baba Ahmed</name>
</wpt>

Can you help me please

alex
  • 5,467
  • 4
  • 33
  • 43

1 Answers1

0

Try this:

line[0] = line[0].replace(/,/g, ".")
line[1] = line[1].replace(/,/g, ".")

This will replace all occurrences of "," in the string instead of just the first one.

Jagdeep Singh
  • 4,880
  • 2
  • 17
  • 22