What is the best way to determine if a string contains a character from a set in Swift

前端 未结 11 1733
南旧
南旧 2020-11-30 01:03

I need to determine if a string contains any of the characters from a custom set that I have defined.

I see from this post that you can use rangeOfString to determine

11条回答
  •  感动是毒
    2020-11-30 01:47

    swift3

    var str = "Hello, playground"
    let res = str.characters.contains { ["x", "z"].contains( $0 ) }
    

提交回复
热议问题