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. Remove Parts of a String
Forum Updated to NodeBB v4.3 + New Features

Remove Parts of a String

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.9k 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.
  • M Offline
    M Offline
    meikelneit
    wrote on 21 Feb 2019, 13:43 last edited by
    #1

    Hello again,

    im Looking to solve the fallowing, and i am Looking for ideas.

    The string Looks like: Eintrag_2 { ExternalWritable := 'False'} : Bool;

    and i want to remove { …} the curly bracket and everything between it. Does that just work with a parser or does the RegularExpressions have some Tools to do the Job?

    K 1 Reply Last reply 21 Feb 2019, 13:58
    0
    • M meikelneit
      21 Feb 2019, 13:43

      Hello again,

      im Looking to solve the fallowing, and i am Looking for ideas.

      The string Looks like: Eintrag_2 { ExternalWritable := 'False'} : Bool;

      and i want to remove { …} the curly bracket and everything between it. Does that just work with a parser or does the RegularExpressions have some Tools to do the Job?

      K Offline
      K Offline
      koahnig
      wrote on 21 Feb 2019, 13:58 last edited by
      #2

      @meikelneit

      This is depending on the complexity of text between curled braces. However, I would try first with QRegularExpression.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      2
      • M Offline
        M Offline
        meikelneit
        wrote on 22 Feb 2019, 09:03 last edited by
        #3

        If someone wants to do the same, i did it with the fallowing Code:

        int l_indexAnfang, l_indexEnde, l_deleteWeite;
        l_indexAnfang = p_String.indexOf(QRegularExpression("{"),0);
        l_indexEnde = p_String.indexOf(QRegularExpression("}"),0);
        l_deleteWeite = l_indexEnde - l_indexAnfang + 1;
        p_String = p_String.remove(l_indexAnfang, l_deleteWeite);

        1 Reply Last reply
        0
        • V Offline
          V Offline
          VRonin
          wrote on 22 Feb 2019, 09:09 last edited by VRonin
          #4

          p_String.replace(QRegularExpression(QStringLiteral("{.*}")),QString());

          https://doc.qt.io/qt-5/qstring.html#replace-12

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          5
          • M Offline
            M Offline
            meikelneit
            wrote on 22 Feb 2019, 10:28 last edited by meikelneit
            #5

            Evene better. What is the Macro inside the Expression good for?

            Does this just "create" the string while compiling so it hasnt to be created in the runtime anymore?

            V 1 Reply Last reply 22 Feb 2019, 11:44
            0
            • M meikelneit
              22 Feb 2019, 10:28

              Evene better. What is the Macro inside the Expression good for?

              Does this just "create" the string while compiling so it hasnt to be created in the runtime anymore?

              V Offline
              V Offline
              VRonin
              wrote on 22 Feb 2019, 11:44 last edited by
              #6

              @meikelneit said in Remove Parts of a String:

              Does this just "create" the string while compiling so it hasnt to be created in the runtime anymore?

              https://woboq.com/blog/qstringliteral.html

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              3
              • M Offline
                M Offline
                meikelneit
                wrote on 22 Feb 2019, 12:22 last edited by meikelneit
                #7

                Thank you very mutch.

                1 Reply Last reply
                0

                1/7

                21 Feb 2019, 13:43

                • 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