let preferredCountryCurrenciesSymbols = ["USD", "EUR", "GBP", "HKD", "JPY", "RUB", "AUD", "CAD"]
let currency = "USDT"
我需要循环数组并在字符串中搜索 .contains 的代码
我已经尝试过这个,但没有找到它
Check if array contains part of a string in Swift?
所以基本上我需要的功能是 -> Bool
有它或没有它。
最佳答案
您链接的问题与您需要的相反。
您可以查找数组中是否有任何值包含在currency
中:
let preferredCountryCurrenciesSymbols = ["USD", "EUR", "GBP", "HKD", "JPY", "RUB", "AUD", "CAD"]
let currency = "USDT"
if preferredCountryCurrenciesSymbols.first(where: { currency.contains($0) }) != nil {
print("found")
} else {
print("not found")
}
关于arrays - 检查数组中的一个元素是否包含在字符串中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57031655/