Wednesday, March 30, 2011

Xcode String Format Error

Hi There, When debugging the following code

NSString *var1 = @"blaa";
NSString *var2 = @"blaaaaa";

NSString* script = [NSString stringWithFormat:@"Set_Variable( %s, %s )",var1,var2];

the %s placehoders in script are replaced with funny gibberish characters. Can you see any errors in the code.

Many thanks, (Confused .NET developer trying to learn objective c :))

Tony

From stackoverflow
  • %s is the format specifier for a C string, char*

    For objective-c objects (such as NSString) you should use %@

    TonyNeallon : wow, that was quick. Thanks a mill Zydeco.

0 comments:

Post a Comment