How to concatenate strings on the iPhone

Objective-C on the iPhone isn’t always the easiest of languages to get you head around. Somethings that are easy in other programming languages can be a bit more obscure.

One thing that I’ve done a lot in VB.Net is string manipulation. It’s easy, straightforward and very powerful!

The documentation around strings is thorough, but lacks enough examples [...]

Objective-C on the iPhone isn't always the easiest of languages to get you head around. Somethings that are easy in other programming languages can be a bit more obscure.

One thing that I've done a lot in VB.Net is string manipulation. It's easy, straightforward and very powerful!

The documentation around strings is thorough, but lacks enough examples of code usage in real life situations!

So, if you need to concatenate two or more strings together, use this example below!

NSString *foobar = [NSString stringWithFormat:@"%@%@", aStringObject, anotherStringObject];

Don't forget to leave a space or spaces, if you want spaces between your strings!

Happy coding!

Cheers

Graham
Tagged with:
 

1 Response » to “How to concatenate strings on the iPhone”

  1. Phloger says:

    You can also use

    NSString* foobar=[aStringObject stringByAppendingString:anotherStringObject];

Leave a Reply




Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!