Objective-C字符串连接

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Objective-C字符串连接相关的知识,希望对你有一定的参考价值。

This is all about appending strings.
  1. /* append to a mutable string */
  2. NSMutableString *aString = [[NSMutableString alloc] initWithString:@"If you don't eat your meat"];
  3. [aString appendString:@" you can't have any pudding."];
  4.  
  5. NSMutableString *bString1 = [[NSMutableString alloc] initWithString:@"We don't need"];
  6. NSMutableString *bString2 = [[NSMutableString alloc] initWithString:@"no education."];
  7. [bString1 appendFormat:@" %@", bString2];
  8.  
  9. /* concatenate 2 strings to make a 3rd */
  10. NSString *string1 = @"This is";
  11. NSString *string2 = @" a test.";
  12. NSString *string3 = [string1 stringByAppendingString:string2];
  13.  
  14. /* assigning an appended string back to itself */
  15. NSString *string1 = @"This is";
  16. NSString *string2 = @" a test.";
  17. string1 = [string1 stringByAppendingString:string2];

以上是关于Objective-C字符串连接的主要内容,如果未能解决你的问题,请参考以下文章

Objective-C字符串连接

将 NSData Objective-C 代码转换为 Swift 时遇到问题

Objective-C Block与函数指针比较

Objective-c:关于self = [super init]的问题

这些角度电子邮件指令代码片段如何连接

在 Rails 上为连接、限制、选择等(不是条件)的 SQL 片段安全地转义字符串