如果我有一个像这样创建的数组:
NSArray* arrItems = [[NSArray alloc] initWithObjects:@"One", @"Two", @"Three", nil];
我有一个具有NSString属性的类:
myClass.myClassString = @"One";
如果我这样做,不应该是isEqualToString:
NSString* strToCheck = myClass.myClassString
for(int i=0; i<arrItems.count; i++) {
NSString* strThisItem = [arrItems objectAtIndex:i];
if ([strThisItem isEqualToString:strToCheck]) {
NSLog(@"Okley dokley!");
}
}
编辑:
真实世界的结果:
在我的应用程序中,我甚至没有获得匹配 - 这是我的注销,包括字符串和它们的长度 - 看看Safety Marketing匹配的位置 - 这里也应该有一个“OK”。
2013-08-28 09:20:02.339 oer[3081:c07] ALDAHOL_7::Safety Marketing_16
2013-08-28 09:20:02.341 oer[3081:c07] ALDAHOL_7::Acecide-C Marketing_19
2013-08-28 09:20:02.341 oer[3081:c07] ALDAHOL_7::ALDAHOL Marketing_17
2013-08-28 09:20:02.342 oer[3081:c07] ALDAHOL_7::OER-Pro Service Marketing_25
2013-08-28 09:20:02.342 oer[3081:c07] Acecide-C_9::Safety Marketing_16
2013-08-28 09:20:02.343 oer[3081:c07] Acecide-C_9::Acecide-C Marketing_19
2013-08-28 09:20:02.343 oer[3081:c07] Acecide-C_9::ALDAHOL Marketing_17
2013-08-28 09:20:02.344 oer[3081:c07] Acecide-C_9::OER-Pro Service Marketing_25
2013-08-28 09:20:02.344 oer[3081:c07] Competitor_10::Safety Marketing_16
2013-08-28 09:20:02.345 oer[3081:c07] Competitor_10::Acecide-C Marketing_19
2013-08-28 09:20:02.345 oer[3081:c07] Competitor_10::ALDAHOL Marketing_17
2013-08-28 09:20:02.345 oer[3081:c07] Competitor_10::OER-Pro Service Marketing_25
2013-08-28 09:20:02.346 oer[3081:c07] Safety_Marketing_16::Safety Marketing_16
2013-08-28 09:20:02.346 oer[3081:c07] Safety_Marketing_16::Acecide-C Marketing_19
2013-08-28 09:20:02.347 oer[3081:c07] Safety_Marketing_16::ALDAHOL Marketing_17
2013-08-28 09:20:02.347 oer[3081:c07] Safety_Marketing_16::OER-Pro Service Marketing_25
2013-08-28 09:20:02.348 oer[3081:c07] Acecide-C_Marketing_19::Safety Marketing_16
2013-08-28 09:20:02.348 oer[3081:c07] Acecide-C_Marketing_19::Acecide-C Marketing_19
2013-08-28 09:20:02.349 oer[3081:c07] Acecide-C_Marketing_19::ALDAHOL Marketing_17
2013-08-28 09:20:02.349 oer[3081:c07] Acecide-C_Marketing_19::OER-Pro Service Marketing_25
2013-08-28 09:20:02.350 oer[3081:c07] ALDAHOL_Marketing_17::Safety Marketing_16
2013-08-28 09:20:02.350 oer[3081:c07] ALDAHOL_Marketing_17::Acecide-C Marketing_19
2013-08-28 09:20:02.351 oer[3081:c07] ALDAHOL_Marketing_17::ALDAHOL Marketing_17
2013-08-28 09:20:02.351 oer[3081:c07] ALDAHOL_Marketing_17::OER-Pro Service Marketing_25
2013-08-28 09:20:02.352 oer[3081:c07] OER-Pro Service_Marketing_25::Safety Marketing_16
2013-08-28 09:20:02.352 oer[3081:c07] OER-Pro Service_Marketing_25::Acecide-C Marketing_19
2013-08-28 09:20:02.353 oer[3081:c07] OER-Pro Service_Marketing_25::ALDAHOL Marketing_17
2013-08-28 09:20:02.353 oer[3081:c07] OER-Pro Service_Marketing_25::OER-Pro Service Marketing_25
答案 0 :(得分:3)
是的,这应该有效。 也许myClass.myClassString在isEqualToString检查之前没有得到你想要的值。
NSLogs打印myClass.myClassString,strToCheck和arrItems可以帮助您找到出错的地方。
现在我看到了你的编辑:
Safety_Marketing_16&lt; - 两个下划线
Safety Marketing_16&lt; - 一个下划线
)
(非常感谢!:D)