QString str = "Hello World!"; if(str.contains("World")){ qDebug() << "String found."; } else { qDebug() << "String not found."; }
QString str = "Hello!"; if(str.contains("!")){ qDebug() << "Character found."; } else { qDebug() << "Character not found."; }The output of this code should be "Character found." In both these examples, the QString contains() function is used to find a specific string or character inside a given string. The QString contains() function is part of the Qt Core library package.