如何将值连接到字符串
我想用逗号作为逗号分隔字符串作为分隔符,并且结果必须存储在字符串中...... comma = @“,”; (i = 0; i < [resources count]; i ++) { Record * aRecord = [resources objectAtIndex:i];如何将值连接到字符串
temp=aRecord.programID;
if(i==0)
pid=temp;
else
//i am using this one to cancatenate but is not working why?
pid = [NSString stringWithFormat:@“%@%@%@”,pid,comma,temp]; }
使用上NSArray
的-componentsJoinedByString:
方法:
NSArray *csvArray = [NSArray arrayWithObjects:@"here", @"be", @"dragons", nil];
NSLog(@"%@", [csvArray componentsJoinedByString:@", "]);
(从the docs)
ishould have to store result in string ... – 2010-08-14 15:42:11
@lak:是的,这样做。这是NSArray上的一个返回NSString的方法。查看文档,或尝试一下。 – 2010-08-14 16:29:03
将id
类型转换为NSString
,然后使用NSString的类引用中找到的级联方法。
你没有说清楚。你有什么形式的字符串串联?你想对结果做什么?显示一些代码。 – 2010-08-14 15:45:47