C中连接NSString的快捷方式

C中连接NSString的快捷方式

本文介绍了Objective-C中连接NSString的快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Objective-C中,是否有任何(stringByAppendingString:)字符串连接的快捷方式,或者通常是与NSString一起使用的快捷方式?

Are there any shortcuts to (stringByAppendingString:) string concatenation in Objective-C, or shortcuts for working with NSString in general?

例如,我要制作:

NSString *myString = @"This";
NSString *test = [myString stringByAppendingString:@" is just a test"];

更像是:

string myString = "This";
string test = myString + " is just a test";

推荐答案

我能想到的两个答案...都不比拥有串联运算符特别令人愉快.

Two answers I can think of... neither is particularly as pleasant as just having a concatenation operator.

首先,使用具有appendString方法的NSMutableString,从而消除了一些额外的临时字符串.

First, use an NSMutableString, which has an appendString method, removing some of the need for extra temp strings.

第二,使用NSArray通过componentsJoinedByString方法进行连接.

Second, use an NSArray to concatenate via the componentsJoinedByString method.

这篇关于Objective-C中连接NSString的快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 03:21