2014-04-14 114 views
0

我需要将一个字符串和一个变量连接在一起 - 我有种发现在变量之前添加字符串的很多示例,但不是另一种方式 - 我该如何执行此操作?iOS:从变量和字符串合并创建字符串

NSString *theImage = [[self.detailItem valueForKey:@" resimagefiletitle"] description], @"'add on the end"; 
+1

我想这是你在找什么。 http://stackoverflow.com/questions/384089/how-should-i-pass-an-int-into-stringwithformat –

+0

欢呼@ungot巴萨 - 基本上我需要这反向即变量然后字符串串 - 不字符串然后变量 - 这是poss? – Dancer

+0

确定这是可能的。只需使用[NSString stringWithFormat:@“%@ string我想在结尾添加”,variableName]。这假定variableName返回一个NSString。 – rdelmar

回答

1

事情是这样的:

NSString *theImage = [NSString stringWithFormat:@"%@ %@",[self.detailItem valueForKey:@" resimagefiletitle"], @"'add on the end"]; 

或者:

NSString *theImage = [NSString stringWithFormat:@"%@ add on the end",[self.detailItem valueForKey:@" resimagefiletitle"]]; 
0

尝试此

的NSString * theImage = [NSString的stringWithFormat:@ “%@“>”,[[self.detailItem valueForKey:@ “resimagefiletitle”]描述]];

在这里我考虑[[self.detailItem valueForKey:@"resimagefiletitle"] description]给出的NSString

0

我们可以通过提Concat的不同势型数据类型转换为字符串格式它。

一样,如果你想两个或多个字符串Concat的在一起,那么你可以使用下面的代码:

的NSString * NewString = [的NSString stringWithFormat:@ “%@%@”,@ “这是” @ “连接字符串的方法”];

如果你想要连续整数值,那么你可以提及它的数据格式“%i”。例如: int OutOf = 150; NSString * NewString = [NSString stringWithFormat:@“%@%i”,@“​​我有100个”,OutOf];

这可能会帮助你。