开发者

removing a specific string from a string and the next string after a space

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 开发者_如何学Gotext @"1.23" varies .. it could be @"1.55" etc. How can i remove the string @"ABC" and the next word after space ?


You can use regular expressions, or you can do that in several ways using NSString methods.

  1. use componentsSeparatedByString and pass a space; your string will be split in an array at word boundaries; then you use componentsJoinedByString: ignoring the first two elements of the array;

  2. 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 the substringFromIndex: 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜