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. Qt Swap numbers places in text

Qt Swap numbers places in text

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 764 Views
  • 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.
  • B Offline
    B Offline
    BORHAN CO.
    wrote on last edited by
    #1

    Hi,
    I have a text documents .İt has numbers that 1234 and ı want to change their places like 2143 how can ı change it ?
    İt was a big problem please help me .

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      You can use std::reverse:

      QString numbers{QLatin1String("1234")};
      std::reverse(numbers.begin(),numbers.end());
      qDebug() << numbers;
      

      "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

      B ODБOïO 2 Replies Last reply
      1
      • VRoninV VRonin

        You can use std::reverse:

        QString numbers{QLatin1String("1234")};
        std::reverse(numbers.begin(),numbers.end());
        qDebug() << numbers;
        
        B Offline
        B Offline
        BORHAN CO.
        wrote on last edited by
        #3

        @VRonin Thank you , but numbers are in text documents and ı dont want to paste them in qt .I want to display them in text edit or something coould you write all code ?

        ODБOïO 1 Reply Last reply
        0
        • VRoninV VRonin

          You can use std::reverse:

          QString numbers{QLatin1String("1234")};
          std::reverse(numbers.begin(),numbers.end());
          qDebug() << numbers;
          
          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by
          #4
           std::reverse(numbers.begin(),numbers.end()-2);
           std::reverse(numbers.begin()+2,numbers.end());
          
          B 1 Reply Last reply
          2
          • B BORHAN CO.

            @VRonin Thank you , but numbers are in text documents and ı dont want to paste them in qt .I want to display them in text edit or something coould you write all code ?

            ODБOïO Offline
            ODБOïO Offline
            ODБOï
            wrote on last edited by
            #5

            @BORHAN-CO. said in Qt Swap numbers places in text:

            but numbers are in text documents

            How your documents are formatted ?
            like this?

            // doc.txt

            "1234"
            "1234"
            "1234"
            "1234"
            
            1 Reply Last reply
            0
            • ODБOïO ODБOï
               std::reverse(numbers.begin(),numbers.end()-2);
               std::reverse(numbers.begin()+2,numbers.end());
              
              B Offline
              B Offline
              BORHAN CO.
              wrote on last edited by
              #6

              @LeLev
              Many thanks for your answer ı solved it with your help :)

              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