来自字符串的子串整数

问题描述:

如何从字符串(我从Sensex网站获得)对整数值进行子串匹配?来自字符串的子串整数

我喜欢“SENSEX:18446.5 * 623.10(3.50)”,我需要的值是18446.5。 在Java中,我可以通过使用subString方法。如何在Objective C中做到这一点?

谢谢:)

+0

如果你想使用子,有3种方法: – 2011-03-01 12:21:38

+0

@ j_freyre - 我的方法,谢谢:) – Akshay 2011-03-01 12:22:39

如果你想使用子,有3种方法,你可以申请一个的NSString:

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

谢谢j_freyre :) – Akshay 2011-03-01 12:25:35

您可以使用一个NSString的substringWithRange:方法。

看看NSString documentation。有很多操作字符串的方法。例如您可以使用componentsSeparatedByString:将您的字符串拆分为一个字符串数组,然后使用floatValue将其中一个字符串转换为数字。

+0

谢谢Ferruccio :) – Akshay 2011-03-01 12:29:13