Get last 2 characters of a string?

前端 未结 2 1151
长情又很酷
长情又很酷 2020-12-24 00:46

Say I have a string:

NSString *state = @"California, CA";

Can someone please tell me how to extract the last two characters from th

相关标签:
2条回答
  • 2020-12-24 01:24
    NSString *code = [state substringFromIndex: [state length] - 2];
    

    should do it

    0 讨论(0)
  • 2020-12-24 01:35

    Swift 4:

    let code = (state as? NSString)?.substring(from: state.characters.count - 2)
    
    0 讨论(0)
提交回复
热议问题