简体   繁体   English

比较可可2D iPhone中的两个字符串

[英]compare two strings in cocos 2D iphone

i am getting ccString through the obstInfo->name . 我正在通过obstInfo->name获取ccString。 now i want to compare it with normal string "eagle".that means i have to compare CCString with normal string. 现在我想将其与普通字符串“ eagle”进行比较。这意味着我必须将CCString与普通字符串进行比较。 in cocos 2D how to compare this. 在cocos 2D中如何比较。

I converted CCString to string through the m_sString & tried belows way but giving error- EXC_bad_access. 我通过m_sStringm_sString转换为字符串,并尝试了以下方法,但给出了错误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. 我到处都用Google搜索,但没有找到正确的搜索结果。

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: 编辑:最近,我在cocos2d-x中与队友一起工作,那时我面临一种情景,其中我必须使两条弦都变通,所以我如下所示:

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"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM