gpt4 book ai didi

iphone - 如何检查字符串中的某些字符?

转载 作者:行者123 更新时间:2023-12-03 20:22:16 25 4
gpt4 key购买 nike

我有一个字符串..

我正在使用该字符串输入用户的一些字符。

现在我想检查该字符串中“a”是否存在?

谁能告诉我该怎么做?

“a”可以出现在字符串中的任何位置。

最佳答案

if ([myString rangeOfString:@"a"].location != NSNotFound) {
// "a" IS in myString
} else {
// "a" ISN'T in myString
}

if ([myString rangeOfString:@"a"].location != NSNotFound && [myString rangeOfString:@"b"].location != NSNotFound) {
// "a" AND "b" are BOTH in myString
} else if ([myString rangeOfString:@"a"].location != NSNotFound) {
// ONLY "a" is in myString
} else if ([myString rangeOfString:@"b"].location != NSNotFound) {
// ONLY "b" is in myString
} else {
// Neither "a" NOR "b" is in myString
}

关于iphone - 如何检查字符串中的某些字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5919728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com