How to remove the first n characters from an NSString

There’s a convenient method for that by the name of substringFromIndex. This example removes the first character:

    NSString *complete = @"12345";
    NSString *cutOff = [complete substringFromIndex:1];
    NSLog(@"%@", cutOff);
    // cutOff is now 2345

substringFromString takes only one parameter which specifies where to start the new string. The first character is 0 based, like in arrays. The parameter can’t be longer than the original string’s length for obvious reasons.





Jay is the CEO and founder of WP Hosting, a boutique style managed WordPress hosting and support service. He has been working with Plesk since version 9 and is a qualified Parallels Automation Professional. In his spare time he likes to develop iOS apps and WordPress plugins, or draw on tablet devices. He blogs about his coding journey at http://wpguru.co.uk and http://pinkstone.co.uk.