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. [SOLVED] QRegExp : remove last character and get path
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QRegExp : remove last character and get path

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 2.1k Views 1 Watching
  • 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
    Raphyy
    wrote on last edited by
    #1

    Hi,

    Pretty much everything is in the title. I'm losing my mind with QRegExp : I tried so many things that I don't know what should I do to solve this.

    I want to do two things:

    1 - Remove a specific character "}" but only when it is at the end of the QStringList. I tried stuff like : @list.replaceInStrings("}$", "");@

    2 - Get the path from a QStringList like "C:\Users\Doe\Desktop\Aaaah.txt" without the filename.

    Thanks for your help !

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      bq. 1 – Remove a specific character “}” but only when it is at the end of the QStringList. I tried stuff like :
      list.replaceInStrings("}$", "");

      You can get last item of the QStringList and check if it is “}” and then remove it from QStringList.

      bq. 2 – Get the path from a QStringList like “C:\Users\Doe\Desktop\Aaaah.txt” without the filename.

      Try

      @QString path = "C:\Users\Doe\Desktop\Aaaah.txt";

      qDebug() << path.section("\",0,-2);
      @

      157

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Raphyy
        wrote on last edited by
        #3

        Thanks for your answer !

        bq. You can get last item of the QStringList and check if it is “}” and then remove it from QStringList

        Yes I could do that, but I don't want to check every element one by one. There must be a nice solution using QRegExp !?

        Your solution for the path is perfect !

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          Ok, Just misunderstood your first question.

          Try this,
          @list = list.replaceInStrings(QRegExp("[}]$"),QString(""));@
          You need to include it in square brackets.

          157

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Raphyy
            wrote on last edited by
            #5

            Nop, it doesn't work, nice try though !

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Raphyy
              wrote on last edited by
              #6

              My bad, your solution works !
              Thanks !

              1 Reply Last reply
              0
              • p3c0P Offline
                p3c0P Offline
                p3c0
                Moderators
                wrote on last edited by
                #7

                Your welcome :)
                You can mark the thread as solved. Just edit the title and prepend it with [solved]

                157

                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