Swift 字符串是否包含某字符

2017-10-10  本文已影响3973人  郭百度

网上很多资料都是错的,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.

上一篇 下一篇

猜你喜欢

热点阅读