//将中文(如'三百二十一')转化成数字(321)
+ (NSString*)convertChineseToNumber:(NSString*)chineseString {
NSDictionary*chineseNumberDict =@{@"零":@(0),@"一":@(1),@"二":@(2),@"两":@(2),@"三":@(3),@"四":@(4),
@"五":@(5),@"六":@(6),@"七":@(7),@"八":@(8),@"九":@(9),
@"十":@(10),@"百":@(100),@"千":@(1000),@"万":@(10000),@"亿":@(100000000)};
if(chineseString.length==0) {
returnnil;
}
NSString*resultString =nil;
if(chineseString.length>0) {
longtotal =0;
intr =1;
for(inti=(int)(chineseString.length-1); i>=0; i--) {
NSString*key = [chineseStringsubstringWithRange:NSMakeRange(i,1)];
intval = [chineseNumberDict[key]intValue];
if(val >=10&&0== i) {
if(val > r) {
r = val;
total += val;
}
else{
r *= val;
}
}
elseif(val >=10) {
if(val > r) {
r = val;
}
else{
r = r * val;
}
}
else{
total = total +r * val;
}
}
resultString = [NSStringstringWithFormat:@"%ld", total];
}
returnresultString;
}
网友评论