Swift 字符串是否包含某字符
程序员文章站
2023-12-21 16:55:16
...
网上很多资料都是错的,Xcode
if string.text!.contains(".") {
print("字符串包含.")
}
附Documentation解释
Finding Substrings
func hasPrefix(String)
Returns a Boolean value indicating whether the string begins with the specified prefix.
func hasSuffix(String)
Returns a Boolean value indicating whether the string ends with the specified suffix.
Finding Characters
func contains(Character)
Returns a Boolean value indicating whether the sequence contains the given element.
func contains(where: (Character) -> Bool)
Returns a Boolean value indicating whether the sequence contains an element that satisfies the given predicate.