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. QString.contains() not entirely specific
Qt 6.11 is out! See what's new in the release blog

QString.contains() not entirely specific

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 917 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.
  • S Offline
    S Offline
    Sucharek
    wrote on last edited by
    #1

    Hi, so I'm making a checking system if something is twice in a file (there is something written in the file, and when I'm inputing something, it checkes if it's there), but it's not entirely specific.
    When I put in a character thats already in the file, it says that it's there (which is supposed to do), but I want to check the whole word, or sentence character by character.
    Is it possible, or not?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What do you mean by checking if it contains a sentence character by character ?

      You can search text for chars, words, group of words.

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

      S 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        What do you mean by checking if it contains a sentence character by character ?

        You can search text for chars, words, group of words.

        S Offline
        S Offline
        Sucharek
        wrote on last edited by
        #3

        Hi @SGaist, I mean that I need to check every character. Lets say you have "A quick red fox jumped over a lazy dog." And you need to check, if its the same, but when I type in "f", it realises that it's in the file, and prints true, which I don't want.
        So, when I have "Ahdeofesl" (just typed something random on my keyboard) in the file, I need to check, if it's the same.

        This might sound confusing, but when you mentioned "a group of words", that might work for me.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Can you explain the workflow ?

          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
          0
          • C Offline
            C Offline
            ChrisW67
            wrote on last edited by
            #5

            If you want to test if two strings are equal then you can just use operator ==.

            If you want to compare character by character for some reason then you can access individual characters using QString::at() or a QString::iterator with a loop and then compare QChars with operator ==.

            S 1 Reply Last reply
            2
            • C ChrisW67

              If you want to test if two strings are equal then you can just use operator ==.

              If you want to compare character by character for some reason then you can access individual characters using QString::at() or a QString::iterator with a loop and then compare QChars with operator ==.

              S Offline
              S Offline
              Sucharek
              wrote on last edited by
              #6

              Hi @ChrisW67, oh yea, I didn't realise, that I could just compare the two strings with ==.
              Thanks for your reply.

              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