从任意字符串中获取所有的数字

直接上源码:

/**
* 从任何字符中读取数字
*
* @param str anyString
*
* @return 所有的数字
*/
-(NSMutableArray *)getAllNumberWithAnyString:(NSString *)str{

NSMutableCharacterSet *set = [NSMutableCharacterSet lowercaseLetterCharacterSet];

[set formUnionWithCharacterSet:[NSCharacterSet uppercaseLetterCharacterSet]];

[set formUnionWithCharacterSet:[NSCharacterSet letterCharacterSet]];

NSMutableArray *contentLines = [[NSMutableArray alloc] initWithArray:[str componentsSeparatedByCharactersInSet:set]];

for (int i=0; i<contentLines.count; i++) {
if ([contentLines[i] isEqualToString:@""]) {
[contentLines removeObjectAtIndex:i];
i--;
}
}
return contentLines;
}

原文地址:https://www.cnblogs.com/wj0920wjx/p/5028250.html