开发者

Substring Integers from String

How can I substring integer values from a string (which I am getting from an Sensex Website) ?

Like : I am getting some values like "SENS开发者_StackOverflow社区EX : 18446.5 * 623.10 (3.50)" the value I need is 18446.5. In java I can do it by using subString method. How to do it in Objective C ?

Thanks :)


If you want to use substring, there is 3 methods that you can apply on a NSString:

- (NSString *)substringFromIndex:(NSUInteger)from;
- (NSString *)substringToIndex:(NSUInteger)to;
- (NSString *)substringWithRange:(NSRange)range; 


You can use the substringWithRange: method on an NSString.

Take a look at the NSString documentation. There is a quite a collection of methods for manipulating strings. e.g. You could use componentsSeparatedByString: to break up your string into an array of strings, and then use floatValue to convert one of those strings to a number.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜