NSMutableString:不需要插入任何值而不是(null)

发布于 2024-11-30 00:54:29 字数 346 浏览 4 评论 0原文

我正在将字符串的值传递给网络服务。如果该字符串具有某些值,那么就可以了。

但如果不包含任何 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜唯美灬不弃 2024-12-07 00:54:29

您可以使用表达式 str1 ?: @"" 来使用字符串,如果为 nil,则使用空字符串。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文