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