Reputation: 1041
How can I compare each character of CCString with each character of other CCString in cocos2dx ?
Thank you
Upvotes: 0
Views: 1937
Reputation: 8896
There is the method in CCString to compare the string
EXample
string1->compare(string2->getCString()); (or whatever the correctly named functions are) that function returns a number, which i think is the difference between the first letter that is wrong, eg a-b = -1 or b-d = 2.. I think this is for sorting things alphabetically... someone correct me if not?
basically if you get 0 from it, then the string is the same all the way through. so:
CCString *string1 = CCString::create("Hi");
CCString *string2 = CCString::create("Hi");
if(string1->compare(string2->getCString()) == 0){
//they are the same
}else{
//different
}
Upvotes: 0
Reputation: 5018
I treat your "compare each character" as "compare equal".
For example:
CCString *pStrA, *pStrB;
string strA = pStrA->toStdString();
string strB = pStrB->toStdString();
if (strA == strB) {
// do something
}
Upvotes: 0
Reputation: 1817
Cocos2dx is based on CPP right? Just get the string to char array and then use ordinary string comparison functions such as strcmp..
Upvotes: 1