Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display the last char of the NSString *

I want to ask a question about the NSString * in objective C. I have an string read from somewhere and I would like to get the last char of that NSString object? I used to try the objectAtIndex, but I don't know what to get the index. What should I type? Thank you very much.

like image 583
Questions Avatar asked Jul 15 '10 01:07

Questions


1 Answers

unichar lastChar = [yourString characterAtIndex:[yourString length] - 1]; 

or if you want it as an NSString:

NSString *lastChar = [yourString substringFromIndex:[yourString length] - 1]; 
like image 187
Wevah Avatar answered Sep 22 '22 15:09

Wevah