How to check what a String starts with (prefix) or ends with (suffix) in Swift

前端 未结 2 497
無奈伤痛
無奈伤痛 2020-12-22 23:31

I\'m trying to test if a Swift string starts or ends with a certain value. These methods do not exist:

var str = \"Hello, playground\"
str.startsWith(\"Hello         


        
2条回答
  •  北海茫月
    2020-12-23 00:00

    Prefix and Suffix Equality

    To check whether a string has a particular string prefix or suffix, call the string’s hasPrefix(:) and hasSuffix(:) methods, both of which take a single argument of type String and return a Boolean value.

    Apple Doc

提交回复
热议问题