How to concatenate two strings on iPhone?

后端 未结 6 1172
既然无缘
既然无缘 2021-02-02 17:27

How to connect string \"Hello\" and string \"World\" to \"HelloWorld\"? Looks like \"+\" doesn\'t work.

6条回答
  •  别那么骄傲
    2021-02-02 18:12

    If you have two literal strings, you can simply code:

    NSString * myString = @"Hello" @"World";
    

    This is a useful technique to break up long literal strings within your code.

    However, this will not work with string variables, where you'd want to use stringWithFormat: or stringByAppendingString:, as mentioned in the other responses.

提交回复
热议问题