i am getting ccString through the obstInfo->name
. now i want to compare it with normal string "eagle".that means i have to compare CCString with normal string. in cocos 2D how to compare this.
I converted CCString to string through the m_sString
& tried belows way but giving error- EXC_bad_access.
string eg="eagle";
string na=obstInfo->name->m_sString;
if( na.compare(eg)==0);
{
}
I googled it everywhere but didn't get correct one.
To compare two string , Use below code
NSString *string1 = @"string1";
NSString *string2 = @"string1";
[string1 isEqualToString:string2]; //this will give true.
EDITED: Recently i was working with my teammates in cocos2d-x and at that time i face one situaltion in which i have to comopare two strings so i did like below:
CCString *str1 = new CCString("abc");
CCstring *str2 = new CCString("abc");
for comparing two strings i did like this:
str1.isEqual(str2);
or you can do like:
Str2.isEqual(new CCString("abc"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.