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. Split a String at prompt "."

Split a String at prompt "."

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 7 Posters 15.6k 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.
  • M meikelneit
    14 Feb 2019, 10:35

    Hello,

    i have a Question About Splitting a string. Is it possible to use the QRegularexpression die split a QString on "."? And when it is possible, how can i do that?

    i Tryed:
    List = String.Split(QRegularExpression(".")), but that does not work.

    R Offline
    R Offline
    Ratzz
    wrote on 14 Feb 2019, 10:42 last edited by Ratzz
    #2

    @meikelneit

    This way ?

    QStringList list1 = str.split('.');

    --Alles ist gut.

    C 1 Reply Last reply 14 Feb 2019, 10:56
    3
    • M Offline
      M Offline
      meikelneit
      wrote on 14 Feb 2019, 10:46 last edited by meikelneit
      #3

      Thank you for this quick answer. I tried that way before but i got a Syntax Error, dont know which one exactly.
      It worked using List = String.Split(QRegularExpression("\\."))

      R 1 Reply Last reply 14 Feb 2019, 10:47
      1
      • M meikelneit
        14 Feb 2019, 10:46

        Thank you for this quick answer. I tried that way before but i got a Syntax Error, dont know which one exactly.
        It worked using List = String.Split(QRegularExpression("\\."))

        R Offline
        R Offline
        Ratzz
        wrote on 14 Feb 2019, 10:47 last edited by
        #4

        @meikelneit said in Split a String at prompt ".":

        . I tried that way before but i got a Syntax Error,

        Did you use .(dot) as a string or char?

        --Alles ist gut.

        1 Reply Last reply
        0
        • R Ratzz
          14 Feb 2019, 10:42

          @meikelneit

          This way ?

          QStringList list1 = str.split('.');
          C Offline
          C Offline
          CP71
          wrote on 14 Feb 2019, 10:56 last edited by
          #5

          @Ratzz
          Hi,
          this works well in my code:

          QStringList data = info.split(";");

          R 1 Reply Last reply 14 Feb 2019, 11:46
          0
          • M Offline
            M Offline
            meikelneit
            wrote on 14 Feb 2019, 11:02 last edited by meikelneit
            #6

            I just hitted my dot button :P, how do i know if its a char or a string? Shall i use the Hexcode of the Ascii?

            ps: yes ";" is no Problem. Try it with "."

            C J R 3 Replies Last reply 14 Feb 2019, 11:12
            0
            • M meikelneit
              14 Feb 2019, 11:02

              I just hitted my dot button :P, how do i know if its a char or a string? Shall i use the Hexcode of the Ascii?

              ps: yes ";" is no Problem. Try it with "."

              C Offline
              C Offline
              CP71
              wrote on 14 Feb 2019, 11:12 last edited by
              #7

              @meikelneit
              I hope I understand your problem, my English isn't good :(
              Anyway, It works well with "."

              0_1550142606010_ca78cde0-2fb8-4702-bbea-c462873db468-image.png

              1 Reply Last reply
              1
              • M meikelneit
                14 Feb 2019, 11:02

                I just hitted my dot button :P, how do i know if its a char or a string? Shall i use the Hexcode of the Ascii?

                ps: yes ";" is no Problem. Try it with "."

                J Offline
                J Offline
                J.Hilk
                Moderators
                wrote on 14 Feb 2019, 11:35 last edited by
                #8

                @meikelneit said in Split a String at prompt ".":

                how do i know if its a char or a string?

                "." -> implicit QString
                '.' -> implicit QChar

                QString(".");
                QChar('.');

                ' more than 1 character' -> Compiler error.


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                4
                • C CP71
                  14 Feb 2019, 10:56

                  @Ratzz
                  Hi,
                  this works well in my code:

                  QStringList data = info.split(";");

                  R Offline
                  R Offline
                  Ratzz
                  wrote on 14 Feb 2019, 11:46 last edited by
                  #9

                  @CP71 said in Split a String at prompt ".":

                  this works well in my code:

                  Are you trying to split an ; ?

                  --Alles ist gut.

                  C 1 Reply Last reply 14 Feb 2019, 13:23
                  0
                  • M meikelneit
                    14 Feb 2019, 11:02

                    I just hitted my dot button :P, how do i know if its a char or a string? Shall i use the Hexcode of the Ascii?

                    ps: yes ";" is no Problem. Try it with "."

                    R Offline
                    R Offline
                    Ratzz
                    wrote on 14 Feb 2019, 11:49 last edited by
                    #10

                    @meikelneit said in Split a String at prompt ".":

                    Try it with "."

                    Split works both with string and char as split has overloads with string and char .

                    --Alles ist gut.

                    1 Reply Last reply
                    1
                    • M Offline
                      M Offline
                      meikelneit
                      wrote on 14 Feb 2019, 11:59 last edited by
                      #11

                      I just can tell u what happens when i try to split with ".".

                      the line i tryed to split is: Array[0..3] of Int;

                      when i use "." is QRegularexpression to split with, i get 21 List Elements and every single one is empty.
                      it wokrs without error, but pls have a look into your listelements, mine were empty, and i had 21 of them, i expected 3.

                      J V 2 Replies Last reply 14 Feb 2019, 12:19
                      0
                      • M meikelneit
                        14 Feb 2019, 11:59

                        I just can tell u what happens when i try to split with ".".

                        the line i tryed to split is: Array[0..3] of Int;

                        when i use "." is QRegularexpression to split with, i get 21 List Elements and every single one is empty.
                        it wokrs without error, but pls have a look into your listelements, mine were empty, and i had 21 of them, i expected 3.

                        J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 14 Feb 2019, 12:19 last edited by
                        #12

                        @meikelneit Can you show your code including the exact string you're trying to split?

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        1
                        • M meikelneit
                          14 Feb 2019, 11:59

                          I just can tell u what happens when i try to split with ".".

                          the line i tryed to split is: Array[0..3] of Int;

                          when i use "." is QRegularexpression to split with, i get 21 List Elements and every single one is empty.
                          it wokrs without error, but pls have a look into your listelements, mine were empty, and i had 21 of them, i expected 3.

                          V Offline
                          V Offline
                          VRonin
                          wrote on 14 Feb 2019, 12:29 last edited by VRonin
                          #13

                          @meikelneit said in Split a String at prompt ".":

                          mine were empty, and i had 21 of them, i expected 3.

                          The second argument to split takes care of this: https://doc.qt.io/qt-5/qstring.html#split-3

                          "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
                          • R Ratzz
                            14 Feb 2019, 11:46

                            @CP71 said in Split a String at prompt ".":

                            this works well in my code:

                            Are you trying to split an ; ?

                            C Offline
                            C Offline
                            CP71
                            wrote on 14 Feb 2019, 13:23 last edited by
                            #14

                            @Ratzz

                            Split function works well in both cases:

                            • QStringList list = text.slit(".");
                            • QStringList list = text.split(";");

                            If it is what you want to know, be patient if I didn't well understand

                            Also I tried:

                            • QStringList list = text.slit(‘.’);
                            • QStringList list = text.split(‘;’);

                            Also in this cases split works well.

                            1 Reply Last reply
                            3
                            • S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 14 Feb 2019, 20:12 last edited by
                              #15

                              Hi

                              @meikelneit said in Split a String at prompt ".":

                              (QRegularExpression(".")

                              The dot in regular expressions means any character. As you discovered, if you want to express a literal dot you have to escape it.

                              You can test your expressions with the QRegularExpression example tool.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              6
                              • M Offline
                                M Offline
                                meikelneit
                                wrote on 18 Feb 2019, 08:23 last edited by
                                #16

                                Thank you very mutch, that explains why i have 21 empty listelements. It just splits between every single character. :) ok thx

                                1 Reply Last reply
                                0

                                11/16

                                14 Feb 2019, 11:59

                                • Login

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