Objective C - How to concatenate an entire array of strings?

房东的猫 提交于 2019-12-03 10:27:14

问题


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?


回答1:


There are many ways to do it, the simplest being

[yourArray componentsJoinedByString: @","]



回答2:


Use NSArray's componentsJoinedByString: method.

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


来源:https://stackoverflow.com/questions/7654679/objective-c-how-to-concatenate-an-entire-array-of-strings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!