如何将值连接到字符串
我想用逗号作为分隔符连接字符串,结果必须存储在字符串中... 逗号=@","; for(i=0;i<[资源数];i++) { 记录 *aRecord = [资源 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,逗号,temp]; }
i want to cancatenate strings with comma as a separator and result must be stored in string...
comma=@",";
for(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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在
NSArray
上使用-componentsJoinedByString:
方法:(来自 文档)
Use the
-componentsJoinedByString:
method onNSArray
:(from the docs)
将
id
类型转换为NSString
,然后使用 NSString 类引用中的串联方法。Cast the
id
types toNSString
and then use the concatenation methods found in the class reference of NSString.