views:

271

answers:

2

Sorry for the dumb question. I have two NSStrings and I want to create a third that is the first string plus a new line 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

+3  A: 

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.

rjstelling
I think there's a typo in your code! You would probably write "\r\n" (CRLF)
BitDrink
Nice spot, now fixed.
rjstelling
Thanks guys, life saver. Up against it at the moment fixing niggles within my code :o)
Magic Bullet Dave
+3  A: 

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

Peter Hosey
This is a great tip, thanks Peter.Dave
Magic Bullet Dave