我正在将数据(从网页)转换为字符串)。基本代码的作品(但有一些微妙的变化 - 可能在服务器上)。“无效”iphone字符串
NSLog显示预期的字符串(可能是1000个字符长)。但是,当我浮动在responseString上时,它显示“无效”。更糟糕的是,使用componentsSeparatedByCharactersInSet解析不起作用。
想法?
NSString *responseString;
responseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
NSLog([NSString stringWithFormat:@"responsestring ='%@'",responseString]);
if ([responseString compare:@""] != NSOrderedSame) {
lines = [responseString componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@";"]];
只需注意您可以使用equalsTo:而不是compare:来比较字符串。那么你不必将它等同于NSOrderedSame。 – rein 2009-08-18 14:31:53
缰 - 谢谢你的提示。与isEqual一起。 – BankStrong 2009-08-18 15:57:24
另外,你的NSLog不需要有stringWithFormat的东西。事实上,那会很糟糕。 NSLog(@“responseString ='%@'”,responseString)会做你想做的事情,因为它自动具有格式。 (之所以不好,是因为responseString,如果它有%,可能会导致你崩溃,因为你可能会传入@“responseString ='一些随机值,其中有'%'” – AlBlue 2009-08-18 20:40:31