Remove last character of NSString

markus picture markus · Oct 4, 2011 · Viewed 59.9k times · Source

I've got some trouble 'ere trying to remove the last character of an NSString. I'm kinda newbie in Objective-C and I have no idea how to make this work.

Could you guys light me up?

Answer

sidyll picture sidyll · Oct 4, 2011
NSString *newString = [oldString substringToIndex:[oldString length]-1];

Always refer to the documentation:


To include code relevant to your case:

NSString *str = textField.text;
NSString *truncatedString = [str substringToIndex:[str length]-1];