Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing the last character from an NSMutableString

Tags:

objective-c

How does one remove the last character from an NSMutableString?

like image 232
some_id Avatar asked Jan 13 '11 00:01

some_id


People also ask

How do you remove the last character of a string in Objective C?

(string. length>0) returns 0 thus making the code return: string = [string substringToIndex:string. length-0];

How do you delete a letter from a string C?

We have removeChar() method that will take a address of string array as an input and a character which you want to remove from a given string. Now in removeChar(char *str, char charToRemove) method our logic is written.


1 Answers

You could use deleteCharactersInRange:

NSMutableString *str = [NSMutableString stringWithString:@"FooBarx"]; [str deleteCharactersInRange:NSMakeRange([str length]-1, 1)]; 
like image 117
Matthias Bauch Avatar answered Oct 10 '22 10:10

Matthias Bauch