Objective-c get last 2 characters of string?

Let's say I have a line:

NSString *state = @"California, CA"; 

Can someone tell me how to extract the last two characters from this line (@ "CA" in this example)

+44
objective-c iphone nsstring
Aug 14 '10 at 12:17
source share
2 answers
 NSString *code = [state substringFromIndex: [state length] - 2]; 

gotta do it

+137
Aug 14 '10 at 12:23
source share

Swift 4:

 let code = (state as? NSString)?.substring(from: state.characters.count - 2) 
0
Oct 20 '17 at 6:07
source share



All Articles