i have a string @”ABC 1.23 bla bla bla” from which i have to remove the @”ABC” string and after that the string @”1.23″. The problem is that the text @”1.23″ varies .. it could be @”1.55″ etc. How can i remove the string @”ABC” and the next word after space ?
Share
You can use regular expressions, or you can do that in several ways using NSString methods.
use
componentsSeparatedByStringand pass a space; your string will be split in an array at word boundaries; then you usecomponentsJoinedByString:ignoring the first two elements of the array;you can use twice in succession
rangeOfString:passing a space in; the first time it will find the space after ABC; the second time, it will find the space after 1.23 (or whatever); then you get thesubstringFromIndex:starting at that position.Regular expression would give you much more options, but it would be a steeper curve, if you have never used regex in ObjC. Have a look at RegExKitLite if you are interested.