NSString长度访问不正确

时间:2011-04-15 15:26:34

标签: objective-c nsstring

NSString *responseData = [request responseString];

我得到一个像(10)这样的字符串。

现在我想删除括号以获取数字。所以我首先想得到字符串的长度

NSLog(@"%@",[responseData length]);

但我得到Thread 1: Program received signal: "EXC_BAD:ACCESS"

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

NSString::length返回无符号整数。所以,试试 -

NSLog(@"%i",[responseData length]); // format specifier is %i and not %@
                                    // Even better if %u is used. 

NSLog format specifiers