NS长度在选中时不正确



我对这个函数有问题:

- (bool) test : (NSString *) chaine
{
    NSLog(@"%i",[chaine length]);
    if([chaine length] == 19) NSLog(@"Test");
}

我的日志中有 19 个,但没有"测试"。所以你知道出了什么问题吗?

多谢

我试过这个

- (void)testFunction{
NSString * aStrFunc= @"StackOverflow";
NSLog(@"%d",[aStrFunc length]);
NSLog(@"%@",[aStrFunc length]==13?@"test right":@"test not right");

}

尝试使用以下代码:

- (bool) test : (NSString *) chaine
{
    //CGFloat len = (float)[chaine length];
    NSUInteger len = [chaine length];
    NSLog(@"%i", len);
    //if (19.0f == len)
    if (19 == len)
    {
        NSLog(@"Test");
    }
}

试试这个

NSData* data=[chaine dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"@s",[data bytes]);//watch the string's bytes possibly you have some unprintable symbols here
if ([data length] == 19) {
NSLog(@"Test");
}

最新更新