Day.01.18 字符串的属性和方法


        //属性
        
//        NSUInteger length = [string length];
        NSUInteger length = string.length;
        
        NSLog(@"%ld",length);
        
        //方法
        
        //判断字符串的内容是否相同
        BOOL isEqual = [string isEqualToString:str2];
        
        NSLog(@"%@",isEqual?@"相同":@"不相同");
        
        //判断字符串的地址是否相同
        NSLog(@"%@",(str2==str4)?@"地址相同":@"地址不同");
        
        //比较字符串的大小 -> 升序 相同 降序
        NSComparisonResult result = [@"aaa" caseInsensitiveCompare:@"bbb"];
        
        switch (result) {
            case NSOrderedAscending:
                NSLog(@"升序");
                break;
            case NSOrderedSame:
                NSLog(@"平序");
                break;
            case NSOrderedDescending:
                NSLog(@"降序");
                break;
                
            default:
                break;
        }
2016-01-18 20:01:34.627 02NSString字符串[3999:614251] 19
2016-01-18 20:01:34.628 02NSString字符串[3999:614251] 不相同
2016-01-18 20:01:34.628 02NSString字符串[3999:614251] 地址不同
2016-01-18 20:01:34.628 02NSString字符串[3999:614251] 升序

你可能感兴趣的:(Day.01.18 字符串的属性和方法)