在做iPhone开发时,经常会碰到要连接多个字符串,以下是本人总结的方法:
NSString *hello=@"Hello,";
NSString *world=@"World!";
NSString *helloWorld;
将hello和world这两个字符串连接。
方法一:helloWorld = [NSString initWithFormat:@"%@%@", hello, world ];
方法二: helloWorld = [hello stringByAppendingString:world];
方法三:helloWorld= [helloWorld stringByAppendingFormat:@"%@%@",hello, world];
方法二效率更高一些。
本文详细介绍了在iOS开发中连接多个字符串的三种方法,并对比了它们的效率,建议使用方法二进行字符串连接。
723

被折叠的 条评论
为什么被折叠?



