Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Incrementing String value
Forum Updated to NodeBB v4.3 + New Features

Incrementing String value

Scheduled Pinned Locked Moved Solved Mobile and Embedded
14 Posts 4 Posters 2.1k 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.
  • VineelaV Vineela

    Well this is my JSON value "INKA010101002020" which is in QByteArray, where I've converted it to QString for substring of last 3 digits "020" then I need to add 1 (auto increment +1) to that 3 digit one, where I've converted it to 'int' but didn't work so any suggestions ??

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @Vineela Something like

    QString str = "INKA010101002020";
    QString subStr = str.right(3);
    int number = subStr.toInt();
    ++number;
    str = str.chopped(3) + QString("%1").arg(number, 3, 10, '0');
    

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    VineelaV 1 Reply Last reply
    3
    • jsulmJ jsulm

      @Vineela Something like

      QString str = "INKA010101002020";
      QString subStr = str.right(3);
      int number = subStr.toInt();
      ++number;
      str = str.chopped(3) + QString("%1").arg(number, 3, 10, '0');
      
      VineelaV Offline
      VineelaV Offline
      Vineela
      wrote on last edited by Vineela
      #3

      @jsulm well this was my answer

      INKA01010100221.000000000000000000000000000000000000000000000000
      I wanted 021 only the last three digits to get added

      J.HilkJ jsulmJ 2 Replies Last reply
      0
      • VineelaV Vineela

        @jsulm well this was my answer

        INKA01010100221.000000000000000000000000000000000000000000000000
        I wanted 021 only the last three digits to get added

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #4

        @Vineela no its not

        0_1547790667101_b5154fc8-b79c-4d14-8a18-a90e2b03785e-image.png

        show us what you're actually doing.


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        VineelaV 1 Reply Last reply
        2
        • VineelaV Vineela

          @jsulm well this was my answer

          INKA01010100221.000000000000000000000000000000000000000000000000
          I wanted 021 only the last three digits to get added

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #5

          @Vineela See the fix from @J-Hilk - for me it is working.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @Vineela no its not

            0_1547790667101_b5154fc8-b79c-4d14-8a18-a90e2b03785e-image.png

            show us what you're actually doing.

            VineelaV Offline
            VineelaV Offline
            Vineela
            wrote on last edited by
            #6

            @J.Hilk oh yes it worked not added QChar at last thanks.

            1 Reply Last reply
            0
            • VineelaV Offline
              VineelaV Offline
              Vineela
              wrote on last edited by Vineela
              #7

              @J-Hilk , @jsulm well INKA010101001 this is my QString value i just want to add 001 to the last so that i get the final value INKA010101001001 like this.

              jsulmJ 1 Reply Last reply
              0
              • VineelaV Vineela

                @J-Hilk , @jsulm well INKA010101001 this is my QString value i just want to add 001 to the last so that i get the final value INKA010101001001 like this.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @Vineela And what is the problem? You can append a string easily to another one...

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                VineelaV 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Vineela And what is the problem? You can append a string easily to another one...

                  VineelaV Offline
                  VineelaV Offline
                  Vineela
                  wrote on last edited by
                  #9

                  @jsulm oh yes ive tried that i got INKA010101001\u0001 this
                  I've used this code

                  QString dd= store;
                    dd.append(001);
                  
                  jsulmJ J.HilkJ 2 Replies Last reply
                  0
                  • VineelaV Vineela

                    @jsulm oh yes ive tried that i got INKA010101001\u0001 this
                    I've used this code

                    QString dd= store;
                      dd.append(001);
                    
                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @Vineela said in Incrementing String value:

                    dd.append(001);

                    dd.append(QLatin1String("001"));

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    VineelaV 1 Reply Last reply
                    1
                    • VineelaV Vineela

                      @jsulm oh yes ive tried that i got INKA010101001\u0001 this
                      I've used this code

                      QString dd= store;
                        dd.append(001);
                      
                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on last edited by J.Hilk
                      #11

                      @Vineela

                      //String concatenation
                      
                      QString a("123");
                      QString b("001");
                      int num =1;
                      
                      QString c = a + b == a.append(b) == a + QString::number(num).rightJustified(3,QChar('0'));
                      
                      

                      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                      Q: What's that?
                      A: It's blue light.
                      Q: What does it do?
                      A: It turns blue.

                      1 Reply Last reply
                      2
                      • jsulmJ jsulm

                        @Vineela said in Incrementing String value:

                        dd.append(001);

                        dd.append(QLatin1String("001"));

                        VineelaV Offline
                        VineelaV Offline
                        Vineela
                        wrote on last edited by
                        #12

                        @jsulm @J-Hilk sorry small change
                        dd.append("001");
                        just this added it worked fine.

                        1 Reply Last reply
                        0
                        • sankarapandiyanS Offline
                          sankarapandiyanS Offline
                          sankarapandiyan
                          wrote on last edited by
                          #13

                          please mark the topic as solved

                          VineelaV 1 Reply Last reply
                          0
                          • sankarapandiyanS sankarapandiyan

                            please mark the topic as solved

                            VineelaV Offline
                            VineelaV Offline
                            Vineela
                            wrote on last edited by
                            #14
                            This post is deleted!
                            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