1
我有一个逻辑条件不起作用。它会比较两个字符,一个来自xml,另一个我自己插入。字符串问题并解析XML
,让你知道我附上代码
NSString *telefono = [NSString stringWithFormat:@"%@", [[arrayColonnine objectAtIndex:indexPath.row]objectForKey:@"telefono"]];
NSString *trimmedTelefono = [telefono stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
senzaTelefono = [[NSString alloc] initWithString:[trimmedTelefono stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
if (telefono == @"NO")
if (trimmedTelefono == @"NO")
if (senzaTelefono == @"NO")
下方为三个字符串,如果我做一个记录它打印NO。但在这三种情况下,如果没有这样的作品。我该如何修复才能使其工作?
SOLUTION
过程仅仅是这样的:
NSString *telefono = [NSString stringWithFormat:@"%@", [[arrayColonnine objectAtIndex:indexPath.row]objectForKey:@"telefono"]];
NSString *trimmedTelefono = [telefono stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if ([trimmedTelefono isEqualToString:@"NO"]) {
//do something...
}
谢谢CocoaFu,我解决了问题,把isEqualToString,但也使用whitespaceAndNewlineCharacterSet – Filippo