How to remove first 3 characters from NSString?

Rahul Vyas picture Rahul Vyas · Jul 2, 2009 · Viewed 71.6k times · Source

I have a string like this "A. rahul VyAs"

and i want to remove "A. " and the space after the "A." so that new string would be "rahul VyAs"

How do i achieve this?

Answer

Alex Rozanski picture Alex Rozanski · Jul 2, 2009

You can use the NSString instance methods substringWithRange: or substringFromIndex:

NSString *str = @"A. rahul VyAs";
NSString *newStr = [str substringWithRange:NSMakeRange(3, [str length]-3)];

or

NSString *str = @"A. rahul VyAs";
NSString *newStr = [str substringFromIndex:3];