The hasSuffix() method checks whether the string ends with the specified string or not.
Example
hasSuffix() Syntax
The syntax of the string hasSuffix() method is:
string.hasSuffix(str: String)
Here, string is an object of the String class.
hasSuffix() Parameters
The hasSuffix() method takes a single parameter:
- str - check whether string ends with str or not
hasSuffix() Return Value
The hasSuffix() method returns:
- true - if the string ends with the given string
- false - if the string doesn't end with the given string
Note: The hasSuffix() method is case-sensitive.
Example 1: Swift string hasSuffix()
Output
true true true false false
Example 2: Using hasSuffix() With if...else
Output
Penned by Kris Some other artist