开发者

Concatenating NSStrings in Objective C

How do I concatenate to NSStrings together in Objective开发者_如何学Python C?


If the string is not mutable, you will instead want:

NSString *firstString = @"FirstString";
NSString *secondString = @"SecondString";
NSString *concatinatedString = [firstString stringByAppendingString:secondString];
// Note that concatinatedString is autoreleased, 
// so if you may want to [concaticatedString retain] it.

For completeness, here's the answer for a mutable string:

NSMutableString *firstString = [NSMutableString stringWithString:@"FirstString"];
NSString *secondString = @"SecondString";
[firstString appendString:secondString];
// Note that firstString is autoreleased, 
// so if you may want to [firstString retain] it.


If you have a mutable string then you can do:

NSMutableString* someString = [NSMutableString stringWithString: @"Hello"];
[someString appendString: @", world!"];

For example. Be more specific if this is not the answer you are looking for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜