问题
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)
回答1:
NSString *code = [state substringFromIndex: [state length] - 2];
should do it
回答2:
Swift 4:
let code = (state as? NSString)?.substring(from: state.characters.count - 2)
来源:https://stackoverflow.com/questions/3483223/objective-c-get-last-2-characters-of-a-string