Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Looking if any character whose ascii code is greater than 127
Forum Updated to NodeBB v4.3 + New Features

Looking if any character whose ascii code is greater than 127

Scheduled Pinned Locked Moved Unsolved General and Desktop
19 Posts 5 Posters 5.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • VRoninV Offline
    VRoninV Offline
    VRonin
    wrote on last edited by
    #10

    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)?

    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
    ~Napoleon Bonaparte

    On a crusade to banish setIndexWidget() from the holy land of Qt

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mulfycrowh
      wrote on last edited by
      #11

      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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mulfycrowh
        wrote on last edited by
        #12

        It's a text file with CR and LF (0d 0a) at the end of each line

        kshegunovK 1 Reply Last reply
        0
        • M mulfycrowh

          It's a text file with CR and LF (0d 0a) at the end of each line

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #13

          @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 ...
          }
          

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          1
          • M Offline
            M Offline
            mulfycrowh
            wrote on last edited by
            #14

            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

            kshegunovK VRoninV 2 Replies Last reply
            0
            • M mulfycrowh

              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

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #15

              @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.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              1
              • M Offline
                M Offline
                mulfycrowh
                wrote on last edited by
                #16

                The trouble is that the file I write to is binary because I append text files and binary files

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mulfycrowh
                  wrote on last edited by
                  #17

                  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;
                  	}
                  
                  1 Reply Last reply
                  0
                  • M mulfycrowh

                    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

                    VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by VRonin
                    #18

                    @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");

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    M 1 Reply Last reply
                    0
                    • VRoninV VRonin

                      @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");

                      M Offline
                      M Offline
                      mulfycrowh
                      wrote on last edited by
                      #19

                      @VRonin Many thanks for your help. I sent you a private message onto your mailbox about another subject. Could you please have a look ?

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved