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. How to validate special characters in QString
Forum Updated to NodeBB v4.3 + New Features

How to validate special characters in QString

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 12.4k 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.
  • I Offline
    I Offline
    Indrajeet
    wrote on last edited by
    #1

    Hi All

    I have QStringList<QString> i want to check if any of the QString has special character in it.
    how to do this?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Define "special characters"?
      Anyway, I guess QRegExp would come to mind, but you will have to do it per QString. No way do it for the whole QStringList in one go.

      1 Reply Last reply
      0
      • I Offline
        I Offline
        Indrajeet
        wrote on last edited by
        #3

        Andre

        Special characters like ! @ # $ % ^ & * ( ) _ +

        Ya i want to do it per QString only.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          So... did you look at [[doc:QRegExp]]?

          1 Reply Last reply
          0
          • I Offline
            I Offline
            Indrajeet
            wrote on last edited by
            #5

            HI Andre

            I went through it but I m not getting.

            I did some thing like this

            QRegExp obj[!,@,#,$,%,^,&,*,(,),_,+];
            Now I m not getting which function to be used to used?
            Please guide.

            1 Reply Last reply
            0
            • I Offline
              I Offline
              Indrajeet
              wrote on last edited by
              #6

              Hi

              If I do like this
              @
              QString str = "123345!";
              int icount = str.count(QRegExp("!"));
              @

              I get icount as 1;

              But I Want to add all special characters in one regular expression and check wether the QString contains anyone of these.How to do this.

              1 Reply Last reply
              0
              • S Offline
                S Offline
                soroush
                wrote on last edited by
                #7

                [quote author="Rajveer" date="1321517103"]Hi

                If I do like this
                @
                QString str = "123345!";
                int icount = str.count(QRegExp("!"));
                @

                I get icount as 1;

                But I Want to add all special characters in one regular expression and check wether the QString contains anyone of these.How to do this.[/quote]

                Try this:

                @
                QString str = "123345!@#$%^&()_+";
                int icount = str.count(QRegExp("[!@#$%^&
                ()_+]"));
                @

                will return 10

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  tobias.hunger
                  wrote on last edited by
                  #8

                  You are aware that QString supports "unicode":http://unicode.org/?

                  Are you sure there are no problematic characters in the non-ASCII range of the unicode table?

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    Indrajeet
                    wrote on last edited by
                    #9

                    Hi

                    How to give multiple filter conditions in one regular expression.
                    Like i wat to filter special characters & alphabets.

                    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