Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Loop trough files and replace variable values between quotes
Qt 6.12 LTS is out! See what's new in the release blog

Loop trough files and replace variable values between quotes

Scheduled Pinned Locked Moved Unsolved General and Desktop
19 Posts 3 Posters 9.3k 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.
  • mrjjM mrjj

    Hmm, dont seem really bad and u use readall so
    relooping the in memory file should be pretty fast?

    How do you recognize pszTimestamp cases?

    ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #7

    @mrjj

    Not yet. Still looking for a way to extract and replace the values that are inside quotes after the first known part of the string.
    If i had such function, it would be easy to exchange all variables from the partially known line

    Hence my question :)

    mrjjM 1 Reply Last reply
    0
    • ? A Former User

      @mrjj

      Not yet. Still looking for a way to extract and replace the values that are inside quotes after the first known part of the string.
      If i had such function, it would be easy to exchange all variables from the partially known line

      Hence my question :)

      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #8

      @WD30EFRX said:
      Well, its a nice problem :)
      Is this something you must do many times since u care about the performance?

      will it always start with "const char* " for those pszTimestamp cases?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #9

        Hi and welcome to devnet,

        You provided only input examples. Can you also provide a complete before/after example ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        ? 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi and welcome to devnet,

          You provided only input examples. Can you also provide a complete before/after example ?

          ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #10

          @SGaist

          Hi!

          The output variables are generated by an external algortithm much like Bitcoin.
          So new hash values and variables need to get 'computed' first and are all related to each other.

          So the output is truly random, the only part that i know for sure are the leading string that identify them in the sources.

          So to shorten my request, what i need is a nice, optimized function to :

          • Open the file
          • Match a whole line by the leading string
          • Split is somewhere after the leading string and replace the variables OR replace with a regex between the quotes
          • Write back to file

          My current code opens every file multiple times for each new string i need to replace.
          So optimized, it would open 1 file and look for ALL the predefined strings i need to replace.

          Hope this helps :)

          Thank you

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #11

            Do you know all the strings you have to search before opening the file ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            ? 1 Reply Last reply
            0
            • SGaistS SGaist

              Do you know all the strings you have to search before opening the file ?

              ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #12

              @SGaist

              Yes i do.

              Thank you

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #13

                Then I'd build something like a vector containing the string/regexp to search along with their replacement and loop on that over a buffer containing your file data. Then you wouldn't need to open every file several times.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                ? 1 Reply Last reply
                0
                • SGaistS SGaist

                  Then I'd build something like a vector containing the string/regexp to search along with their replacement and loop on that over a buffer containing your file data. Then you wouldn't need to open every file several times.

                  ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #14

                  @SGaist

                  Thank you.

                  Right now i'm looking to replace the fixed lines using their known line numbers, split the strings, extract the values and join them back.

                  This seems to work. However, i have several multiline codeblocks that needs replacement between {}, and now i'm stucked with those. :)

                  1 Reply Last reply
                  0
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #15

                    Hi
                    several multiline codeblocks ?
                    That is a new type it seems?

                    ? 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      Hi
                      several multiline codeblocks ?
                      That is a new type it seems?

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #16

                      @mrjj

                      As example:

                      int64_t DoSomeFunctionHere(int64_t param1, int64_t param2)
                      {
                          Some line of code here
                          Some line of code here
                          return Param1 + Param2;
                      }
                      

                      So i need to look for DoSomeFunctionHere and replace everything that follows inside the { and }

                      1 Reply Last reply
                      0
                      • mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #17

                        Ok, so that is still "0x0" type
                        for "Some line of code here"
                        or new case?

                        ? 1 Reply Last reply
                        0
                        • mrjjM mrjj

                          Ok, so that is still "0x0" type
                          for "Some line of code here"
                          or new case?

                          ? Offline
                          ? Offline
                          A Former User
                          wrote on last edited by
                          #18

                          @mrjj

                          It's combined. But i think i'll look for someone to hire to complete my project since my deadline is very near :)

                          mrjjM 1 Reply Last reply
                          0
                          • ? A Former User

                            @mrjj

                            It's combined. But i think i'll look for someone to hire to complete my project since my deadline is very near :)

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #19

                            @WD30EFRX
                            Ok that could be an option too,
                            If u use something like
                            https://www.freelancer.com

                            Make sure to describe the problem very carefully with
                            actual samples of what to find and what to replace with and the
                            different cases. Also what " first known part of the string." is. and so on.
                            Also, if the files are in subfolder etc.

                            Else you wont get a good estimate of the cost.

                            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
                            • Unsolved