2

I'm currently working on a project in Qt, where the user can enter a value in a configuration to set it as global. This Value wll be stored in an .xml file where it is read from as well.

Because of me using c++ in Visual Studio, it only accepts a point: 14.6 is ok but 14,6 isn't. It doesn't throw an error, but the value will be saved as zero. I want to keep it in the xml in the format with the point, for language reasons (German is the only language that needs a comma until this point, and the most languages use the point as separator as well)

I search something similar to : Replace ,(comma) by .(dot) and .(dot) by ,(comma) . This answer referes to Javascript but I need it in c++.

I would like to know what would be the most efficient solution. I have alredy thought about "translating" it with regular expressions but I'm sure there are way more elegent and shorter ways of doing this.

Farhad
  • 4,119
  • 8
  • 43
  • 66

1 Answers1

1

It's easy to use std::replace function:

QString s = "aaa,bbb,ccc";
std::replace(s.begin(), s.end(), ',', '.');
qDebug()<< s;

OR QString replace function:

QString s = "aaa,bbb,ccc";
s.replace(",", ".");
qDebug()<< s;

Output: aaa.bbb.ccc

Farhad
  • 4,119
  • 8
  • 43
  • 66