Unsolved Looking if any character whose ascii code is greater than 127
-
How can I post the content of the file ?
-
We just want to understand what's in that file. is it a .txt file containing text, is it a binary file (image, document, etc)?
-
Here is the start of the file:
@Comt = Based on L : Litolff’s / 1880 B : Breitkopf / 1890 P : Peters / 1892
The trouble is the character ' after Litolff
-
It's a text file with CR and LF (0d 0a) at the end of each line
-
@mulfycrowh
If you have a text file, then read it as a text file! Why are all those shenanigans even needed?QFile file("C:/path/to/file"); if (!file.open(QFile::ReadOnly | QFile::Text)) //< Open as text file so you get CL/LF conversions properly ; //< Can't open file, handle accordingly QTextStream in(&file); while (!in.atEnd()) { QString line = in.readLine(); // ... do something with he line ... }
-
At the very beginning, I read it as a text file. The problem was that I got LF instead CR LF and I need CR LF to rewrite the file content into another file
-
@mulfycrowh
That's because there are line ending conversions done depending on the OS. It's not a problem!
You read it as a text file, and you get "\n" where the newline is. When you write it as a text file "\r\n" will be written wherever there's "\n". That's the difference between text and binary files. -
The trouble is that the file I write to is binary because I append text files and binary files
-
It runs if I use this:
bool Tools::searchIncoherentAscii(const QString &content) { int j; for (int i = 0; i < content.length(); i++) { j = content.at(i).unicode(); if ( j > 127) return true; }
-
@mulfycrowh said:
The problem was that I got LF instead CR LF and I need CR LF to rewrite the file content into another file
use
QString::replace("\n","\r\n");
-
@VRonin Many thanks for your help. I sent you a private message onto your mailbox about another subject. Could you please have a look ?