美文网首页
Swift 字符串是否包含某字符

Swift 字符串是否包含某字符

作者: 郭百度 | 来源:发表于2017-10-10 16:11 被阅读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.

相关文章

网友评论

      本文标题:Swift 字符串是否包含某字符

      本文链接:https://www.haomeiwen.com/subject/xizvyxtx.html