将 kABPersonPhoneProperty 转换为阿拉伯数字 [英] convert kABPersonPhoneProperty to arabic numbers

查看:85
本文介绍了将 kABPersonPhoneProperty 转换为阿拉伯数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从电话通讯录中读取电话号码,有些号码以非阿拉伯数字形式保存在那里,即(١٢٣٤٥٦٧٨٩)我如何将这些数字转换为阿拉伯数字(123456789)

I'm reading phone numbers from the phone address book , some numbers are saved there in non arabic numbers i.e ( ١٢٣٤٥٦٧٨٩ ) how can i convert these numbers to arabic numbers ( 123456789 )

这就是我提取数字的方式

that's how i extract the numbers

    CFTypeRef phoneProperty = ABRecordCopyValue(record, kABPersonPhoneProperty);
    NSArray *phones = (__bridge_transfer NSArray *)ABMultiValueCopyArrayOfAllValues(phoneProperty);

现在手机包含电话号码作为 NSString 对象

now phone contains phone numbers as NSString objects

推荐答案

已测试:

-(NSString*)arabicToWestern:(NSString)numericString {
   NSMutableString *s = [NSMutableString stringWithString:numericString];
   NSString *arabic = @"١٢٣٤٥٦٧٨٩";
   NSString *western = @"123456789";
   for (uint i = 0; i<arabic.length; i++) {
      NSString *a = [arabic substringWithRange:NSMakeRange(i, 1)];
      NSString *w = [western substringWithRange:NSMakeRange(i, 1)];
      [s replaceOccurrencesOfString:a withString:w 
                            options:NSCaseInsensitiveSearch
                              range:NSMakeRange(0, s.length)];
   }
   return [NSString stringWithString:s];
}

这篇关于将 kABPersonPhoneProperty 转换为阿拉伯数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆