Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Compare two Qstrings? [closed]

I have to compare two Qstrings in qt,

say,

Qstring str1="1005",str2="1006"; 

I have tried using ,

if(str1==str2){    return true; } 

&

if(str1.compare(str2)==0) {     return true; } 

still both methods goes inside if condition & returns true.

like image 466
krohit Avatar asked Oct 09 '13 06:10

krohit


People also ask

How do you compare Qstring?

Using String. equals() :In Java, string equals() method compares the two given strings based on the data/content of the string. If all the contents of both the strings are same then it returns true. If any character does not match, then it returns false.

Can I use == to compare strings in Java?

You should not use == (equality operator) to compare these strings because they compare the reference of the string, i.e. whether they are the same object or not. On the other hand, equals() method compares whether the value of the strings is equal, and not the object itself.

Which is the correct way of comparing the contents of the below strings?

The right way of comparing String in Java is to either use equals(), equalsIgnoreCase(), or compareTo() method. You should use equals() method to check if two String contains exactly same characters in same order. It returns true if two String are equal or false if unequal.


1 Answers

You can use :

int x = QString::compare(str1, str2, Qt::CaseInsensitive);  // if strings are equal x should return 0 
like image 161
mcelik Avatar answered Sep 29 '22 09:09

mcelik