说我有一个字符串:
NSString *state = @"California, CA";
有人可以告诉我如何从这个字符串中提取最后两个字符(在本例中为@“CA”)
答案 0 :(得分:150)
NSString *code = [state substringFromIndex: [state length] - 2];
应该这样做
答案 1 :(得分:0)
Swift 4:
let code = (state as? NSString)?.substring(from: state.characters.count - 2)