Swift 字符串是否包含某字符

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 夕阳落,皎月升空。歌声起,何人与听。皓色千里清辉。影无尘,止行举首。亦可见、星月相拥。荷花凋零,朔风未凛、年年望月...
    微诗人阅读 3,021评论 0 1
  • 上山的人别嘲笑下山的人,因为他们曾经风光过;山上的人也别嘲笑上山的人,因为他们有一天也会上山来。
    小袁小袁努力向前阅读 2,682评论 1 3
  • 高中老师曾教导我们:好逸恶劳,人之本性。某商业大腕说:聪明人都会偷懒。说的都是一码事,但懒和偷懒就不是一码事了,至...
    512song阅读 3,214评论 0 0
  • ——谨以此文献给蹉跎岁月 在看《奇葩说》里讨论的议题,“没有上进心的我有错吗?”于是,我开始思考,上进心是...
    周溜遛阅读 3,192评论 9 1

友情链接更多精彩内容