PDA

View Full Version : Need support in removing the Carriage Returns



kaml.mish
28th March 2015, 05:39
Hello All
As part of json response, I am getting a QString with multiple carriage returns.
I need support in removing them , as the string is of quite a big size.
I tried using


QString::simplified
QString::remove(QRegExp(["\r\n]));

Please find the string attached as a file.

wysota
28th March 2015, 07:13
QString::siimplified() should work, it should leave you with one newline everywhere. If you want to remove all newlines then use QString::remove() passing '\n' as the frst argument. However I don't understand why you'd want to remove those new lines.

jefftee
28th March 2015, 07:26
If you use the QJsonDocument, QJsonArray, and QJsonObject classes, it should simplify your parsing of the JSON data. If you need to store the JSON response in a compact format, the QJsonDocument::toJson() method has an argument that determines whether the resulting string is QJsonDocument::Indented (formatted with line breaks and indenting) or QJsonDocument::Compact (no formatting or line beaks).

Disregard if you're using an old version of Qt that doesn't have the QJson* classes, but if possible, these will simplify your life!