Get last 2 characters of a string?

Viewed 46572

Say I have a string:

NSString *state = @"California, CA";

Can someone please tell me how to extract the last two characters from this string (@"CA" in this example).

2 Answers

Swift 4:

let code = (state as? NSString)?.substring(from: state.characters.count - 2)
Related