Check if string has suffix

 Problem

I have a string and want to check if there is a specific suffix.



 Recipe


// String literal
var a = "Hello World!"

// Check if there is a specific Suffix

if a.hasSuffix("World!") {
    print("Yes, there is")
}
else {
    print("Error!")
}

				

Heard the news?

The Swift Cookbook for Swift 3 is at last here! For iBooks, Kindle and Paperback.
Hurry up - and Check it out! ;-)

 

 Playground