2

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

Like : I am getting some values like "SENSEX : 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 :)

Akshay
  • 2,973
  • 6
  • 43
  • 75

2 Answers2

3

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; 
j_freyre
  • 4,623
  • 2
  • 30
  • 47
1

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.

Ferruccio
  • 98,941
  • 38
  • 226
  • 299