Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove prefix from NSString

How can I delete the prefix "test" from a NSString? I've tried stringByReplacingOccurrencesOfString: but it's not what I want because it's the prefix that I want to remove not from the other occurrences of the string.

like image 327
atomikpanda Avatar asked Sep 15 '12 12:09

atomikpanda


1 Answers

NSString *prefixToRemove = @"test"; NSString *newString = [originalString copy]; if ([originalString hasPrefix:prefixToRemove])     newString = [originalString substringFromIndex:[prefixToRemove length]]; 
like image 152
DrummerB Avatar answered Oct 08 '22 22:10

DrummerB