黑马程序员技术交流社区

标题: OC中怎么比较两个字符串啊? [打印本页]

作者: ydy2511000    时间: 2016-1-11 22:55
标题: OC中怎么比较两个字符串啊?
刚刚看完第一天视频=。=
@interface Car:NSObject
{
    NSString *_color;
}
-(void)compareColor:(NSString *)other;
@end

@implementation dog
-(void)compareColor:(NSString *)other
{
     if(strcmp(_color,other) == 0)   //主要是这里怎么写啊???strcmp(const char *,const char *)这里老是不对。。。。求解,是不是要用C来写char*???
     {
       NSLog(@"1");
     }else
    {
    NSLog(@"0");
    }
}
@end


作者: 一步步往上爬    时间: 2016-1-13 13:08
直接写成 if(_color==other)
作者: 364827317    时间: 2016-1-13 16:18
实现类怎么是dog
作者: ydy2511000    时间: 2016-1-14 14:15
364827317 发表于 2016-1-13 16:18
实现类怎么是dog

写错了=。= Car




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2