2个相同字符串的比较

时间:2010-10-29 14:13:49

标签: iphone objective-c

我疯了 - 这两个字符串是相同的,但是代码会因为它们不同而回来!:

NSLog(@"nearbyAirport %@", nearbyAirport.geocode);
NSLog(@"airportToFind %@", airportToFind.geocode);

//Try and match geocodes.  If they are the same then airport is valid
if ([[airportToFind geocode] isEqualToString:[nearbyAirport geocode]])
{
return YES;
}

2010-10-29 15:10:59.808 Name[10658:207] nearbyAirport 6296598
2010-10-29 15:11:00.235 Name[10658:207] airportToFind 6296598

3 个答案:

答案 0 :(得分:2)

在字符串周围添加引号以确保没有空格。我对地理编码一无所知,他们总是一个数字吗?你能将它们转换为NSNumber并进行整数比较吗?

答案 1 :(得分:2)

[airportToFind geocode]的类型是什么?

是否实施isEqualToString:

答案 2 :(得分:1)

不确定为什么那不起作用。既然它们是数字,也许可以尝试将字符串转换为整数并将它们进行比较?

if ([[airportToFind geocode] intValue] == [[nearbyAirport geocode] intValue]) {
     return YES;
     NSLog(@"Success!");
}
相关问题