欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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.

上一篇:

下一篇: