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 "."
Forum Updated to NodeBB v4.3 + New Features

Split a String at prompt "."

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 7 Posters 15.9k Views 2 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 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("\\."))

    RatzzR 1 Reply Last reply
    1
    • M meikelneit

      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("\\."))

      RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on 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
      • RatzzR Ratzz

        @meikelneit

        This way ?

        QStringList list1 = str.split('.');
        CP71C Offline
        CP71C Offline
        CP71
        wrote on last edited by
        #5

        @Ratzz
        Hi,
        this works well in my code:

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

        RatzzR 1 Reply Last reply
        0
        • M Offline
          M Offline
          meikelneit
          wrote on 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 "."

          CP71C J.HilkJ RatzzR 3 Replies Last reply
          0
          • M meikelneit

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

            CP71C Offline
            CP71C Offline
            CP71
            wrote on 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

              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.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on 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
              • CP71C CP71

                @Ratzz
                Hi,
                this works well in my code:

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

                RatzzR Offline
                RatzzR Offline
                Ratzz
                wrote on 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.

                CP71C 1 Reply Last reply
                0
                • M meikelneit

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

                  RatzzR Offline
                  RatzzR Offline
                  Ratzz
                  wrote on 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 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.

                    jsulmJ VRoninV 2 Replies Last reply
                    0
                    • M meikelneit

                      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.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 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

                        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.

                        VRoninV Offline
                        VRoninV Offline
                        VRonin
                        wrote on 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
                        • RatzzR Ratzz

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

                          this works well in my code:

                          Are you trying to split an ; ?

                          CP71C Offline
                          CP71C Offline
                          CP71
                          wrote on 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
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 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 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

                              • Login

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