Important: Please read the Qt Code of Conduct -

QString.contains() not entirely specific

  • 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?

  • Lifetime Qt Champion


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

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

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

  • Lifetime Qt Champion

    Can you explain the workflow ?

  • 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 ==.

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

Log in to reply