objective-c获得一个string的最后2个字符?
说我有一个string:
NSString *state = @"California, CA";
有人可以告诉我如何从这个string中提取最后两个字符(在这个例子中是@“CA”)
NSString *code = [state substringFromIndex: [state length] - 2];
应该这样做
Swift 4:
let code = (state as? NSString)?.substring(from: state.characters.count - 2)