OC NSString练习

练习下api,但mentor说api可以后置,先学习语法和框架思想,感觉相当有道理,所以api就先不练了,用到再临时看

int main(int argc, const char * argv[]) {
    int num = 6;
    num = 5;
    printf("%d\n", num);
    char arr[10] = "fucku";
    NSString *str;
    str = [NSString stringWithCString: arr encoding: 4];    //encoding: (NSStringEncoding是interger)
    str = [NSString stringWithFormat: @"i love u and %@ %d %s", str, 677456, arr];  //stringWithFormat: (format) parm1 parm2...
    NSString *str2 = [NSString stringWithString: str];
    NSString *str3 = [NSString stringWithFormat: @"%@", str];
    NSLog(@"%d", str == str2); //true:证明stringWithString是浅拷贝
    NSLog(@"%d", str == str3); //false:证明stringWithFormat是深拷贝
    str2 = @"abc";
    str3 = @"abd";
    NSComparisonResult res = [str2 compare: str3];  //compare:比较两个字符串的字典序大小关系
    if (res == NSOrderedSame) {
        printf("same\n");
    } else if (res == NSOrderedAscending) {
        printf("后面大\n");
    } else {
        printf("前面大\n");
    }
    NSString *string15 = @"www.baidu.com";
    NSString *string16 = [@"http://" stringByAppendingString:string15];//直接把两个字符串连接起来,调用者在前,传进来的字符串在后
    NSLog(@"%@",string16);
    NSLog(@"%@", str);
    
}

 

posted @ 2020-12-01 16:25  NeoZy  阅读(166)  评论(0编辑  收藏  举报