I can reproduce the following C#/.NET:
//A
String.Format("There are {0} cats in my {1} and no {2}", 2, "house", "dogs");
in Objective-C/Cocoa:
//B
[NSString stringWithFormat:@"There are %d cats in my %@ and no %@", 2, "house", "dogs"];
But I can't do this:
//C
String.Format("I have {0} dogs in my house. My {0} dogs are very nice, but it is hard to walk {0} dogs at the same time.", numDogs);
in Objective-C:
//D
[NSString stringWithFormat:@"I have %d dogs in my house. My %d dogs are very nice, but it is hard to walk %d dogs at the same time.", numDogs];
because it uses the printf format or whatever. Is there a more advanced way of doing this? Is there some way of doing KVC in string-parsing?
This is technically what I'd like:
[player setValue:@"Jimmy" forKey@"PlayerName"];
//later
[NSString stringWithMagicFormat:@"<PlayerName> sat on a bench in the middle of winter, and <GenderPronoun> felt very cold." andPlayer:player];
// or
[NSString stringwithMagicFormat: playerEnteredStringWithTagInIt andPlayer:player];
But I'll settle for:
String.Format(playerEnteredStringWithTagInIt, player.PlayerName, player.PlayerGender, player.GenderPronoun, ...);
Thanks,