Objective c NSString长度在选中时不正确?

Objective c NSString长度在选中时不正确?,objective-c,nsstring,Objective C,Nsstring,我对此功能有问题: - (bool) test : (NSString *) chaine { NSLog(@"%i",[chaine length]); if([chaine length] == 19) NSLog(@"Test"); } 我的日志中有19个,但不是“测试”。你知道怎么了吗 非常感谢尝试使用以下代码: - (bool) test : (NSString *) chaine { //CGFloat len = (float)[chaine length

我对此功能有问题:

- (bool) test : (NSString *) chaine
{
    NSLog(@"%i",[chaine length]);
    if([chaine length] == 19) NSLog(@"Test");
}
我的日志中有19个,但不是“测试”。你知道怎么了吗

非常感谢

尝试使用以下代码:

- (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");
    }
}
请尝试使用以下代码:

- (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");
}
试试这个

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");
}
我试过这个

- (void)testFunction{
NSString * aStrFunc= @"StackOverflow";

NSLog(@"%d",[aStrFunc length]);

NSLog(@"%@",[aStrFunc length]==13?@"test right":@"test not right");
}我试过这个

- (void)testFunction{
NSString * aStrFunc= @"StackOverflow";

NSLog(@"%d",[aStrFunc length]);

NSLog(@"%@",[aStrFunc length]==13?@"test right":@"test not right");

}

你确定你发布了你试图运行的确切代码吗?我想知道如果你将
[chaine length]
转换为
(int)[chaine length]
,会发生什么情况。这个方法中没有
return
吗?如果使用
if([chaine length]==19L),会发生什么情况
?不知道为什么这个问题被否决。你确定你发布了你试图运行的确切代码吗?我想知道如果你将
[chaine length]
强制转换为
(int)[chaine length]
。你没有
返回此方法中的某个地方吗?如果使用
if([chaine length]==19L),会发生什么情况
?不知道这个问题为什么会被否决。。你为什么要用“==”来比较浮点值?@GoroshkoPavel-你现在的代码实际上与OP中的代码相同。它有什么帮助?你为什么要用“=”来比较浮点值?@GoroshkoPavel-您现在的代码实际上与OP中的代码相同。它应该有什么帮助?这无法解释为什么[string length]在连续行中看起来不同。这无法解释为什么[string length]在连续行中看起来不同。