• home
  • products
  • bosshogg's blog
  • forums
  • about
  • contact us
Home › Blogs › bosshogg's blog

User login

  • Create new account
  • Request new password

Formatting NSString's With NSStrings

bosshogg — Fri, 11/27/2009 - 15:23

Disclaimer:Perhaps everyone else in the iPhone-Development-Universe learned this nugget in some obvious Apple programming tutorial, but for some reason, it took quite a bit of hunting the other day for me to find it. So, I now post this here for the bumpkins like myself that had trouble finding it. For those non-bumpkins, just keep moving. Nothing for you to see here.

I (like most iPhone developers) pass around strings using the built-in NSString class. Overall, NSString is a very full-featured string class with a large breadth and depth of functionality. One particular function that I was hunting for the other day was the ability to insert an NSString into another NSString ala the old C sprintf function. So, after some hunting, here it is. %@
There you have it. %@. Not much to it but if you don't know what it is, you may never guess it. If what I'm saying doesn't make sense, then perhaps the following code snippet will:

NSString* string1 = @"Jon";
NSString* formattedString = [NSString stringWithFormat:@"Hello %@"];

That snippet will of course insert "Jon" into the other NSString. And as you would expect, all the other standard C formatting escape sequences will also work such as %d, %u, %c, etc, etc. Anyway, hopefully this helps someone. If nothing else, when I forget I can just return to this post the next time I forget!

  • bosshogg's blog
  • Login or register to post comments

Navigation

  • Forums
  • Recent posts
  • Feed aggregator

New forum topics

  • Crash on 10,000 Lite Version 1.6
  • Crash on 1st gen iPhone, looking for iAd framework
  • One thing missing...
  • Hello from my iPad
  • Welcome NetDetective Users!
more

Recent blog posts

  • How the iPad Killed Our iPhone App Sales
  • Sending email from within iPhone apps
  • iPhone Tie Down Calculator Created for Pacific Cargo Control
  • My Opinings On The iPad
  • Plug For A Good Small Company
  • Gambling Planet Features Three Jacks Games
  • Twist Tac Toads Available in the AppStore!
  • Getting the Version String
  • Your iPhone App Icon
  • C++ On The iPhone
more

© Copyright 2009. All rights reserved.

  • home
  • products
  • bosshogg's blog
  • forums
  • about
  • contact us