首页 > 代码库 > Object-c 之 字符串
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; }
运行结果
Object-c 之 字符串
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。