首页 > 其他 > 详细

Object-c 之 字符串

时间:2014-07-21 22:15:38      阅读:352      评论:0      收藏:0      [点我收藏+]
#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 之 字符串

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!