TonyNeallon
TonyNeallon

Reputation: 6607

stringWithFormat produces string with gibberish characters

When debugging the following code

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

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

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

Upvotes: 3

Views: 8523

Answers (1)

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

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

Upvotes: 12

Related Questions