Get last 2 characters of a string?
Objective CNsstringObjective C Problem Overview
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).
Objective C Solutions
Solution 1 - Objective C
NSString *code = [state substringFromIndex: [state length] - 2];
should do it
Solution 2 - Objective C
Swift 4:
let code = (state as? NSString)?.substring(from: state.characters.count - 2)