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 762 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.
  • AzadshahrA Offline
    AzadshahrA Offline
    Azadshahr
    wrote on 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.

    JonBJ 1 Reply Last reply
    0
    • AzadshahrA Azadshahr

      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.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on 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
      • AzadshahrA Offline
        AzadshahrA Offline
        Azadshahr
        wrote on last edited by
        #3

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

        JonBJ 1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 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
          • AzadshahrA Azadshahr

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

            JonBJ Online
            JonBJ Online
            JonB
            wrote on 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
            • Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 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

              JonBJ 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @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.

                JonBJ Online
                JonBJ Online
                JonB
                wrote on 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 :/.

                Christian EhrlicherC 1 Reply Last reply
                1
                • JonBJ JonB

                  @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 :/.

                  Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 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

                  • Login

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