Objective C - 如何连接整个字符串数组?

发布于 2024-12-08 08:33:08 字数 121 浏览 2 评论 0原文

我是 Objective C 新手。我想编写一个方法,它接受一个字符串数组并返回一个连接字符串,每个字符串之间有一个逗号 (,)。 所以如果一个数组是{abcd},我想返回a,b,c,d。

最简单的方法是什么?

I am an Objective C newbie. I want to write a method that takes in an array of strings and returns a concatenated string, with a comma (,) in between each string.
So if an array is {a b c d}, I want to return a,b,c,d.

What is the easiest way to do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

中二柚 2024-12-15 08:33:08

方法有很多种,最简单的就是

[yourArray componentsJoinedByString: @","]

There are many ways to do it, the simplest being

[yourArray componentsJoinedByString: @","]
梦里的微风 2024-12-15 08:33:08

使用 NSArray 的 componentsJoinedByString: 方法。

NSArray *strings = ...;
NSString *combined = [strings componentsJoinedByString:@","];

Use NSArray's componentsJoinedByString: method.

NSArray *strings = ...;
NSString *combined = [strings componentsJoinedByString:@","];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文