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. How can you cut a string up to a certain number character C++ QT

How can you cut a string up to a certain number character C++ QT

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 588 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.
  • R Offline
    R Offline
    RuWex
    wrote on 2 Nov 2022, 06:50 last edited by
    #1

    if my QT doesnt know the function sliced()
    for example I have this string:
    "gt200"
    and I want to get the string 200 and to cast it to int.
    and always the string before the int its 2 letters.
    how can I do it without sliced()?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on 2 Nov 2022, 07:46 last edited by
      #6

      Yes you will get yy=300.
      Just try the code yourself :)

      R 1 Reply Last reply 2 Nov 2022, 07:46
      1
      • B Offline
        B Offline
        Bonnie
        wrote on 2 Nov 2022, 07:17 last edited by
        #2

        use QString::mid()

        1 Reply Last reply
        1
        • R Offline
          R Offline
          RuWex
          wrote on 2 Nov 2022, 07:22 last edited by
          #3

          @Bonnie
          thank,
          but is it good if I dont know the num of the numbers- its can be -1 and its can be 467434...??
          and other question,
          how can \i get the number as int?
          I know in visual studio use atoi()
          how can I do it in QT?

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Bonnie
            wrote on 2 Nov 2022, 07:37 last edited by Bonnie 11 Feb 2022, 07:41
            #4

            You ask for something equivalent to slice() (in javascript right?), that's it. It doesn't care the characters are numbers or not.
            mid(2) will just get you a substring from index 2 to the end of the string.
            And Qt has QString::toInt() , QString::toUInt(), QString::toLong(), etc..

            R 1 Reply Last reply 2 Nov 2022, 07:43
            1
            • B Bonnie
              2 Nov 2022, 07:37

              You ask for something equivalent to slice() (in javascript right?), that's it. It doesn't care the characters are numbers or not.
              mid(2) will just get you a substring from index 2 to the end of the string.
              And Qt has QString::toInt() , QString::toUInt(), QString::toLong(), etc..

              R Offline
              R Offline
              RuWex
              wrote on 2 Nov 2022, 07:43 last edited by RuWex 11 Feb 2022, 07:44
              #5

              @Bonnie thank,
              but my question:
              if for example I have :
              QString xx= "gt300"
              int yy= xx.mid(2).toInt.
              I will get 300 or the convertion of this characters?

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Bonnie
                wrote on 2 Nov 2022, 07:46 last edited by
                #6

                Yes you will get yy=300.
                Just try the code yourself :)

                R 1 Reply Last reply 2 Nov 2022, 07:46
                1
                • B Bonnie
                  2 Nov 2022, 07:46

                  Yes you will get yy=300.
                  Just try the code yourself :)

                  R Offline
                  R Offline
                  RuWex
                  wrote on 2 Nov 2022, 07:46 last edited by
                  #7

                  @Bonnie thank!!

                  1 Reply Last reply
                  0

                  1/7

                  2 Nov 2022, 06:50

                  • Login

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