开发者

Concatenating two NSStrings separated by a CRLF

Sorry for the dumb question. I have two NSStrings and I want to create a third that is the first string plus a new lin开发者_开发百科e plus the second string. I know this must be easy but I am banging my head looking for it.

Ultimately I want the resulting string to display correctly in a table view cell.

Regards

Dave


For an arbitrary number of strings, put them in an array and send it a componentsJoinedByString: message, passing the CRLF string (@"\r\n").


You best bet is to use stringWithFormat:

NSString *newString = [NSString stringWithFormat:@"%@\r\n%@", firstString, secondString];

When putting this into a table cell, you might have to set the numberOfLines property and override the - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath method.

And don't for get to release you strings when done.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜