放置在哪里||

发布于 2024-11-30 01:38:58 字数 144 浏览 2 评论 0原文

我知道这是一个非常简单的问题,但是我应该将 || 放在哪里如果我想同时检查 CAF 和 AAC,可以在下面查看吗?谢谢!

if ([[file pathExtension] isEqualToString:@"caf"])

I know that this is a really simple question, but where should I place the || below if I want to check for both CAF and AAC? Thanks!

if ([[file pathExtension] isEqualToString:@"caf"])

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

翻身的咸鱼 2024-12-07 01:38:58
if ([[file pathExtension] isEqualToString:@"caf"] || [[file pathExtension] isEqualToString:@"aac"])
if ([[file pathExtension] isEqualToString:@"caf"] || [[file pathExtension] isEqualToString:@"aac"])
2024-12-07 01:38:58
if ([[file pathExtension] isEqualToString:@"caf"] ||
    [[file pathExtension] isEqualToString:@"aac"] )

注意 - 这是文字比较,因此它不区分大小写 - 如果您想进行不区分大小写的比较:

if ([[file pathExtension] compare:@"caf" options:NSCaseInsensitiveSearch] == NSOrderedSame || 
    [[file pathExtension] compare:@"aac" options:NSCaseInsensitiveSearch] == NSOrderedSame)
if ([[file pathExtension] isEqualToString:@"caf"] ||
    [[file pathExtension] isEqualToString:@"aac"] )

Note - this is a literal comparison so it is not case insensitive - if you want to do a case insensitive comparison:

if ([[file pathExtension] compare:@"caf" options:NSCaseInsensitiveSearch] == NSOrderedSame || 
    [[file pathExtension] compare:@"aac" options:NSCaseInsensitiveSearch] == NSOrderedSame)
三五鸿雁 2024-12-07 01:38:58

您必须测试两次:

if ([[file pathExtension] isEqualToString:@"caf"] ||
    [[file pathExtension] isEqualToString:@"aac"])

或者,通过这样做来避免重复:

NSString *ext = [file pathExtension];
if ([ext isEqualToString:@"caf"] ||
    [ext isEqualToString:@"aac"])

You have to test it twice:

if ([[file pathExtension] isEqualToString:@"caf"] ||
    [[file pathExtension] isEqualToString:@"aac"])

Or, avoid some repetition by doing it like:

NSString *ext = [file pathExtension];
if ([ext isEqualToString:@"caf"] ||
    [ext isEqualToString:@"aac"])
栩栩如生 2024-12-07 01:38:58

|| 在 Objective c 中表示“或”。所以这个 if (a == 1 || a == 2) 意味着如果 a 等于 1 OR a 等于 2。所以:

== equal

&&和

||或者

|| means 'or' in Objective c. So this if (a == 1 || a == 2) means if a is equal to 1 OR a is equal to 2. So:

== equal

&& and

|| or

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