码迷,mamicode.com
首页 > 其他好文 > 详细

Object-c 之 字符串

时间:2014-07-21 22:15:38      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:object-c

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{

    @autoreleasepool {
        NSString *s1;
        s1=[NSString stringWithFormat:@"%d + %d = %d",2,3,2+3];
        NSLog(@"%@",s1);
        NSLog(@"length:%ld",[s1 length]);
        
        NSString *s2=@"2 + 3 = 5";
        if([s1 isEqualToString:s2]){
            NSLog(@"s1 isEqualToString:s2");
        }else{
            NSLog(@"s1 isNotEqualToString:s2");
        }
        
        if(s1 == s2){
            NSLog(@"s1 == s2");
        }else{
            NSLog(@"s1 != s2");
        }
        
        if([s1 compare:s2]){
            NSLog(@"s1 compare s2");
        }else{
            NSLog(@"s1 not compare s2");
        }
        
        
        //拼接字符串
        NSString *s3 =[NSString stringWithFormat:@"%@%@",s1,s2];
        NSLog(@"%@",s3);
        
        s3=@"";
        s3=[s1 stringByAppendingString:s2];
        NSLog(@"%@",s3);

    }
    return 0;
}


运行结果

bubuko.com,布布扣

Object-c 之 字符串

标签:object-c

原文地址:http://blog.csdn.net/lihuozhiling0101/article/details/38022091

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!