How to concatenate strings (i.e. print several at a time)

This is really simple in PHP, however it’s not obvious in Objective-C because you’re not printing the strings directly. Rather you print two objects that point to each string. There is a method though which has the same effect: stringByAppendingString. Here’s how you use it:

It gets a bit more complex when you want to add three or more together; each stringByAppendingString expression needs to be in [brackets] before you add another one, like so:

About Jay Versluis

Jay is a medical miracle known as Super Survivor. He runs two YouTube channels, five websites and several podcast feeds. To see what else he's up to, and to support him on his mission to make the world a better place, check out his Patreon Campaign.

2 thoughts on “How to concatenate strings (i.e. print several at a time)

  1. If you just want to print several strings that don’t necessarily have to become a single new string you can also choose to print them like this:

    The %@ will be replaced with nameString. You can add as many as you like.

  2. Alternatively, we can format a string with another string, like this:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.