开发者

Get last 2 characters of a string?

开发者 https://www.devze.com 2023-01-12 01:45 出处:网络
Say I have a string: NSString *state = @"California, CA"; Can 开发者_Python百科someone please tell me how to extract the last two characters from this string (@"CA" in this exampl

Say I have a string:

NSString *state = @"California, CA";

Can 开发者_Python百科someone please tell me how to extract the last two characters from this string (@"CA" in this example).


NSString *code = [state substringFromIndex: [state length] - 2];

should do it


Swift 4:

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

精彩评论

暂无评论...
验证码 换一张
取 消