Objective c 如何将数组元素连接成字符串?
我有一个字符串,它的值类似于FirstName;姓氏;电话,例如Objective c 如何将数组元素连接成字符串?,objective-c,xcode4,Objective C,Xcode4,我有一个字符串,它的值类似于FirstName;姓氏;电话,例如 Tom;Hanks;12346789 Tom,Hanks 我正在填充一个UIVewTable标签文本,该文本应为FirstName,LastName,例如 Tom;Hanks;12346789 Tom,Hanks 然后,我把手机的细节位 我正在基于半列拆分字符串然后将数组的前两个元素、逗号和description中的第三个元素连接起来。 它工作得很好,但我认为数组元素的串联可能不是最好的方法,或者说通常的方法看起来像是一种
Tom;Hanks;12346789
Tom,Hanks
我正在填充一个UIVewTable标签文本,该文本应为FirstName,LastName,例如Tom;Hanks;12346789
Tom,Hanks
然后,我把手机的细节位
我正在基于半列拆分字符串
然后将数组的前两个元素、逗号和description中的第三个元素连接起来。它工作得很好,但我认为数组元素的串联可能不是最好的方法,或者说通常的方法看起来像是一种攻击。我能找人帮忙把它弄好吗。我的代码如下
NSArray *title = [[dataArray objectAtIndex:indexPath.row] componentsSeparatedByString:@";"];
//This bit below does not look right.
cell.textLabel.text = [[[title objectAtIndex:0] stringByAppendingString:@","] stringByAppendingString:[title objectAtIndex:1]];
cell.detailTextLabel.text = [title objectAtIndex:2];
稍微好一点的解决方案:
cell.textLabel.text = [NSString stringWithFormat:@"%@,%@", [title objectAtIndex:0], [title objectAtIndex:1]];
稍微好一点的解决方案:
cell.textLabel.text = [NSString stringWithFormat:@"%@,%@", [title objectAtIndex:0], [title objectAtIndex:1]];