NSMutableString:不需要插入任何值而不是(null)
我正在将字符串的值传递给网络服务。如果该字符串具有某些值,那么就可以了。
但如果不包含任何 null 值,则打印 (null)。
例如:
NSMutableString *str1 = [NSMutableString stringWithFormat:@""];
NSString *string = [NSString stringWithFormat:@"str1 has %@ value", str1];
NSLog(@"%@", string);
应该打印 : str1 has value
而不是打印: str1 has (null) value
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用表达式
str1 ?: @""
来使用字符串,如果为 nil,则使用空字符串。You can use the expression
str1 ?: @""
to use the string, or an empty string if it's nil.