objective-c - iPhone : How to get the currency symbol from an amount string?

标签 objective-c ios

我有一个不同货币金额的列表(例如 10.99 美元、20.55 欧元)。我想找出每个字符串的货币符号,以便解析金额。

你有什么想法吗?

问候。

最佳答案

您可以使用正则表达式查找第一个不是数字或小数分隔符的符号:

NSError *error = NULL;
NSRegularExpression *symbol= [NSRegularExpression
    regularExpressionWithPattern:@"[^0-9.,]"
    options:NSRegularExpressionCaseInsensitive
    error:&error];
NSRange r = [symbol
    rangeOfFirstMatchInString:myString
    options:0
    range:NSMakeRange(0, [myString length])];
if (!NSEqualRanges(r, NSMakeRange(NSNotFound, 0))) {
    NSLog(@"Currency symbol is '%@'", [myString substringWithRange:r]);
}

关于objective-c - iPhone : How to get the currency symbol from an amount string?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10384863/

相关文章:

ios - 如何通过在一个屏幕中导航用户来阻止用户

ios - NSValue valueWithCATransform3D : in Swift3

objective-c - UIViewController 的 View 有奇怪的 20px y 边距

ios - 选择表格 View 单元格时无法推送我的 View Controller

objective-c - 为从 NSObject 子类化的 Swift 类的实例属性提供自定义后备存储

iphone - 如何防止 iOS 上的格式字符串攻击和缓冲区溢出?

ios - Swift版本嵌入外部Framework

ios - 表格 View 在 iPhone 上放错了位置

ios - 了解 iOS 中的 iBeacons : didDetermineState and didEnterRegion events

iphone - UICollectionView 内容在 reloadData 后被隐藏