1

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

Joris Ooms
  • 11,880
  • 17
  • 67
  • 124
Hanuman
  • 642
  • 5
  • 19
  • 1
    It prints "str1 has value" for me, like you'd expect. Are you sure the problem isn't elsewhere? – Tommy Aug 17 '11 at 20:55

1 Answers1

4

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

jtbandes
  • 115,675
  • 35
  • 233
  • 266