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. Select a substring in QString
Forum Updated to NodeBB v4.3 + New Features

Select a substring in QString

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 706 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.
  • A Offline
    A Offline
    Azadshahr
    wrote on 30 Jun 2020, 15:39 last edited by
    #1

    I have a string like "//Machine/C://DriveOne/File1". I wanted to select this part "DriveOne/File1" from that string. How can I do that? I have defined these strings a QString.

    J 1 Reply Last reply 30 Jun 2020, 15:45
    0
    • A Azadshahr
      30 Jun 2020, 15:39

      I have a string like "//Machine/C://DriveOne/File1". I wanted to select this part "DriveOne/File1" from that string. How can I do that? I have defined these strings a QString.

      J Offline
      J Offline
      JonB
      wrote on 30 Jun 2020, 15:45 last edited by
      #2

      @Azadshahr
      Before anyone answers this, are you sure about the C:// bit? Sure it isn't:

      //Machine/C:/DriveOne/File1"
      

      ?

      1 Reply Last reply
      1
      • A Offline
        A Offline
        Azadshahr
        wrote on 30 Jun 2020, 16:01 last edited by
        #3

        Yeah. It is "//Machine/C:/DriveOne/File1" correct. Sorry. However, I wanted to select "DriveOne/File1".

        J 1 Reply Last reply 30 Jun 2020, 16:17
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 30 Jun 2020, 16:04 last edited by
          #4

          Simply split the string at "//" maybe?

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0
          • A Azadshahr
            30 Jun 2020, 16:01

            Yeah. It is "//Machine/C:/DriveOne/File1" correct. Sorry. However, I wanted to select "DriveOne/File1".

            J Offline
            J Offline
            JonB
            wrote on 30 Jun 2020, 16:17 last edited by JonB
            #5

            @Azadshahr
            I suspected so :) I asked because now looking for // isn't going to help you.

            So you can either split at/index from :/, or use QRegularExpression depending on just what you want to allow for.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 30 Jun 2020, 16:35 last edited by
              #6

              @JonB said in Select a substring in QString:

              I asked because now looking for // isn't going to help you.

              Why not? Simply split, take the last one.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              J 1 Reply Last reply 30 Jun 2020, 17:31
              0
              • C Christian Ehrlicher
                30 Jun 2020, 16:35

                @JonB said in Select a substring in QString:

                I asked because now looking for // isn't going to help you.

                Why not? Simply split, take the last one.

                J Offline
                J Offline
                JonB
                wrote on 30 Jun 2020, 17:31 last edited by JonB
                #7

                @Christian-Ehrlicher
                Have you seen that the OP confirmed the string is:

                //Machine/C:/DriveOne/File1
                

                Not as originally posted; there is no longer // in the middle. And he wants back:

                DriveOne/File1
                

                Which is why I said split on :/.

                C 1 Reply Last reply 30 Jun 2020, 18:07
                1
                • J JonB
                  30 Jun 2020, 17:31

                  @Christian-Ehrlicher
                  Have you seen that the OP confirmed the string is:

                  //Machine/C:/DriveOne/File1
                  

                  Not as originally posted; there is no longer // in the middle. And he wants back:

                  DriveOne/File1
                  

                  Which is why I said split on :/.

                  C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 30 Jun 2020, 18:07 last edited by
                  #8

                  @JonB Ah, sorry - but the logic is the same :)

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0

                  1/8

                  30 Jun 2020, 15:39

                  • Login

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