Ios 转换用户';s的电话号码转换成英文号码

Ios 转换用户';s的电话号码转换成英文号码,ios,objective-c,Ios,Objective C,我有一个应用程序,用户必须插入他的号码并将其发送到服务器。 我遇到的问题是,一些用户用他们的母语(例如乌尔都语、阿拉伯语、印度语或其他语言)插入数字 我想要的是将所有不同语言的数字转换成英文数字(1,2,3…),然后发送到服务器。 有没有一种可能的方法来实现这一点 提前谢谢你。如果你不能做到 NSInteger blah = [enteredString intValue]; // you will have to know if it's an int, float, double, etc.

我有一个应用程序,用户必须插入他的号码并将其发送到服务器。 我遇到的问题是,一些用户用他们的母语(例如乌尔都语、阿拉伯语、印度语或其他语言)插入数字 我想要的是将所有不同语言的数字转换成英文数字(1,2,3…),然后发送到服务器。 有没有一种可能的方法来实现这一点


提前谢谢你。

如果你不能做到

NSInteger blah = [enteredString intValue];
// you will have to know if it's an int, float, double, etc...
// the entered number is still a number just using a different font (I guess).
// the shape of the number 2 comes entirely from the font so I don't see why this wouldn't work
但是如果这不起作用,请查看
NSNumberFormatter
类。你应该可以做一些像

NSNumberFormatter *nf = [NSNumberFormatter new];
NSNumber *number = [nf numberFromString:enteredString];
任何一种方法都应该有效。先试试第一个。如果这不起作用,那么试试数字格式化程序。您可能需要设置数字格式化程序的区域设置

通过工作项目进行测试

// This is the only code.
#import "ViewController.h"

@interface ViewController () <UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextField *textField;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self getNumber];
    return YES;
}

- (void)getNumber
{
    NSInteger number = [self.textField.text intValue];

    NSLog(@"%ld", (long)number);
}

@end
//这是唯一的代码。
#导入“ViewController.h”
@界面视图控制器()
@属性(弱,非原子)IBUITEXTFIELD*textField;
@结束
@实现视图控制器
-(无效)viewDidLoad{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
}
-(无效)未收到记忆警告{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
-(BOOL)textField应返回:(UITextField*)textField
{
[自选号码];
返回YES;
}
-(void)getNumber
{
NSInteger number=[self.textField.text intValue];
NSLog(@“%ld”(长)编号);
}
@结束
我将模拟器语言改为阿拉伯语,效果非常好

截图。。。

代码。。。

文字字符串与输入字符串的比较

我猜这是因为你的开发语言是英语

无论如何,当您输入文本字符串
١时‎٢‎٣
到Xcode中并将其存储在字符串中,这与获取字符串不同‎٢‎٣来自阿拉伯语文本字段


请注意,这与
xcode
IDE无关,因此我删除了该标记。请您也分享一下您尝试过的代码好吗?例如,输入应该是“一百二十三”(英语)或“einhunderdreiundzwanzig”(德语)?不,如果用户输入@“٠١”,我的意思是什么‎٢‎٣“应该发送到服务器的真实数字将为@“0123”,作为提醒:您还必须检查服务器端的输入。因此,始终假定发送到服务器的数据可能已损坏。另外:为什么要将数字作为字符串发送?如果将其转换为实际数字格式,可以节省一些字节(并避免字符格式问题)。请稍候。。。你用这个来打电话号码吗?i、 e.用户输入的电话号码是多少?如果是这样的话,提到这一点就太棒了,因为电话号码与实际电话号码大不相同。您好,NSString*arabicNumb=@“٠١”‎٢‎٣٤‎٥‎٦‎٧٨"; NSInteger intValue=[arabicNumb intValue];NSLog(@“整数%d”,intValue)//返回1个NSNumberFormatter*nf=[NSNumberFormatter new];NSNumber*number=[nf numberFromString:arabicNumb];NSLog(@“格式化程序%@”,编号)//这又回来了null@IphoneUser您是否将设备的语言环境设置为您使用的数字的语言环境?是的,我设置了,但仍然得到空响应。@IphoneUser我刚刚设置了一个带有文本字段的演示项目。将(模拟器)设备语言更改为阿拉伯语,并输入“123”。这两种方法都很有效。你用阿拉伯语输入123了吗?所以文本字段text是١‎٢‎٣?