//自己写的于大家分享
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSString *str=@"101000001011";
NSArray *arr1=@[@"零",@"壹",@"贰",@"叁",@"肆",@"伍",@"陆",@"柒",@"捌",@"玖"];
NSArray *arr2=@[@"仟",@"佰",@"万",@"仟",@"佰",@"拾",@"亿",@"仟",@"佰",@"拾",@"万",@"仟",@"佰",@"拾",@"圆整"];
NSMutableString *str1=[NSMutableString string];
if (str.length>arr2.count) {
NSLog(@"输入有误");
}else{
for (int i=0; i<str.length-1; i++) {
int index1=(int)[str characterAtIndex:i]-48;
[str1 appendString:arr1[index1]];
int index2=arr2.count-str.length;
[str1 appendString:arr2[index2+i]];
}
int index1=(int)[str characterAtIndex:str.length-1]-48;
if (index1==0) {
[str1 appendString:arr2[arr2.count-1]];
}else{
[str1 appendString:arr1[index1]];
[str1 appendString:arr2[arr2.count-1]];
}
}
NSLog(@"%@",str1);
}
return 0;
}
|