0

I'm new to Objective-C and I couldn't find a direct solution for my problem where it is explained how to add string behind or in front of an array value . I try to get some text from an array and add some other string behind or infront of it (will be used in tableviewcell). In Android it's working just with + signs, that's why I couldn't handle it here. I try to do something like below:

"some text" +[arrayName objectAtIndex:indexPath.row] + "some text"
ysnsyhn
  • 457
  • 1
  • 6
  • 12

2 Answers2

1

You need to use stringWithFormat to concatenate those values, or you can use NSMutableString as well

Use this

NSString* finalText = [NSString stringWithFormat:@"some text %@ some text",[arrayName objectAtIndex:indexPath.row]];

Another way

NSMutableString* finalString = [NSMutableString stringWithString:@"test Text"];
[finalString appendString:[arrayName objectAtIndex:indexPath.row]];
[finalString appendString:@"test Text 2"];
Reinier Melian
  • 20,519
  • 3
  • 38
  • 55
0

Short:

[NSString stringWithFormat:@"%@/%@/%@", "some text", [arrayName objectAtIndex:indexPath.row], "some text"];

For further answers see: https://stackoverflow.com/a/510444/9310455

Davide
  • 26
  • 5