附加字符串

时间:2011-12-27 06:32:59

标签: objective-c cocoa-touch iphone-sdk-3.0

我知道这对某人来说很容易。我需要组合对象来制作一个地址。我不知道该怎么做。我试过......

    NSString *agcstr = [infoDictionary objectForKey:@"physstr"];
NSString *agccity = [infoDictionary objectForKey:@"physcity"];
NSString *agcstate = [infoDictionary objectForKey:@"physstate"];
NSString *agczip = [infoDictionary objectForKey:@"physzip"];

dvController.agcaddress = [agcstr stringByAppendingString:@"\n"     stringByAppendingString:agccity stringByAppendingString:@", " stringByAppendingString:agczip];

这是完全错误但我总是至少尝试一些事情:)

2 个答案:

答案 0 :(得分:3)

尝试stringWithFormat

dvController.agcaddress = [NSString stringWithFormat:@"%@, %@, %@, %@", agcstr, agccity, agcstate, agczip];

答案 1 :(得分:0)

请尝试以下方法:

NSString *agcstr = [infoDictionary objectForKey:@"physstr"];
NSString *agccity = [infoDictionary objectForKey:@"physcity"];
NSString *agcstate = [infoDictionary objectForKey:@"physstate"];
NSString *agczip = [infoDictionary objectForKey:@"physzip"];

dvController.agcaddress = [[[[agcstr stringByAppendingString:@"\n"] stringByAppendingString:agccity] stringByAppendingString:@", "] stringByAppendingString:agczip];

可替换地,

dvController.agcaddress = [NSString stringWithFormat:@"%@ \n %@, %@", agcstr, agccity, agczip];