Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 377
TonyNeallon Avatar asked Sep 13 '26 03:09

TonyNeallon


1 Answers

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

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

like image 68
Jesús A. Álvarez Avatar answered Sep 14 '26 15:09

Jesús A. Álvarez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!