如何在objective-c中组合字符串和变量

如何在objective-c中组合字符串和变量,objective-c,Objective C,我想将标签的文本更改为: 变量+字符串+变量。 我该怎么做呢 self.yesNo.text = [NSString stringWithFormat:_variable, @" is divisible by " , variable]; 这就是我目前所知道的,但是有很多错误。我能做什么?试试这个: [NSString stringWithFormat: @"%d is divisible by %d", _variable, variable]; 使用字符串显示变量的以下方法: int

我想将标签的文本更改为:

变量+字符串+变量。

我该怎么做呢

self.yesNo.text = [NSString stringWithFormat:_variable, @" is divisible by " , variable];
这就是我目前所知道的,但是有很多错误。我能做什么?

试试这个:

[NSString stringWithFormat: @"%d is divisible by %d", _variable, variable];

使用字符串显示变量的以下方法:

int variable = 15
NSString *string = @"Jaspidis Z."
[NSString stringWithFormat:@"%d %@ %d",variable , string,variable]

output :  15 Jaspidis Z. 15 

文件规定:

+ (instancetype)stringWithFormat:(NSString *)format
其中
格式是

格式字符串。有关如何使用此方法的示例,请参见格式化字符串对象,有关格式说明符列表,请参见字符串格式说明符。此值不能为零

例如:

NSString *string1 = [NSString stringWithFormat:@"A string: %@, a float: %1.2f", @"string", 31415.9265];


谢谢!它真的很好用!然后接受答案。:)