开发者

How can I concatenate array elements into a string?

开发者 https://www.devze.com 2023-04-10 20:17 出处:网络
I have string whose value are like FirstName;LastName;Phone e.g. Tom;Hanks;12346789 I am populating a UIVewTable Label text is suposed to be FirstName,LastName e.g.

I have string whose value are like FirstName;LastName;Phone e.g.

Tom;Hanks;12346789

I am populating a UIVewTable Label text is suposed to be FirstName,LastName e.g.

Tom,Hanks

Then I put the phone in details bit.

I am splitting the String based on semiColumn ; then concatenating the first two elements of array and comma and third element in description.

It is working fine but I think the concatenation of array elements is not probably the best or normal way seems like a hack. Can I please get somehelp getting it right. My code is below

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];
开发者_运维知识库


Slightly better solution:

cell.textLabel.text = [NSString stringWithFormat:@"%@,%@", [title objectAtIndex:0], [title objectAtIndex:1]];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号