过滤NSMutableArray并仅返回数字

时间:2014-05-17 12:38:07

标签: objective-c nsmutablearray

我有一个名为 myMutableArray 的NSMutableArray,我有以下数值:

('R$ 118.98','AE 12.00 er','R$ 456.99')

我会做的是找到一种方法来过滤此数组中包含的信息,从而使其仅返回数字字符,例如:

('118.98','12.00','456.99')

我有一个简单的代码来获取数组中的行:

for(int x=0; x<[myMutableArray count]; x++){

myMutableArray[x];//We need to find a way to filter and update this informations to only store numbers.

}

我可以在代码中添加什么代码来过滤数组中的信息以仅存储数字?

1 个答案:

答案 0 :(得分:3)

尝试:

//create a new mutable array to store the modified values
NSMutableArray *arrFinal = [[NSMutableArray alloc] init];

//fast-enumerate within myMutableArray
for (NSString *strCurrent in myMutableArray) {
    NSString *strModified = [strCurrent stringByTrimmingCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]];

    [arrFinal addObject:strModified];
}

NSLog(@"%@",[arrFinal description]);
相关问题