Get last 2 characters of a string?

前端 未结 2 1161
长情又很酷
长情又很酷 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:35

    Swift 4:

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

提交回复
热议问题