Search code examples
iphoneobjective-ciosnsmutablestring

NSMutableString: Need to insert no value instead of (null)


I am passing the value of string to a web service. if the string has some value then it is ok.

but if does not contain any value which is null, it prints (null).

for eg:

NSMutableString *str1 = [NSMutableString stringWithFormat:@""];
NSString *string = [NSString stringWithFormat:@"str1 has %@ value", str1];

NSLog(@"%@", string);

Should print : str1 has value

instead it prints: str1 has (null) value


Solution

  • You can use the expression str1 ?: @"" to use the string, or an empty string if it's nil.