Ios 如何将字母数字字符串转换为数字字符串或数字?

Ios 如何将字母数字字符串转换为数字字符串或数字?,ios,objective-c,Ios,Objective C,我想把字母数字字符串转换成数字。字母数字字符串包含数字集[0-9]、大写字母集[A-Z]和小写字母集[A-Z],分别为数字[00-09]、[10-35]和[36-62] 每个字母或数字必须生成两位数字,如果字母为“y”,则数字为“61”或字母为“C”,则数字为“12”,或数字为“6”,则数字为“06” 例如: 字母数字字符串:“yc69CJjVvf” 数字:61380609121945315841按字符遍历字符串,如果字符是符号转换为数字字符串,如果字符是数字而不是格式(“0%d”),将结果累加

我想把字母数字字符串转换成数字。字母数字字符串包含数字集[0-9]、大写字母集[A-Z]和小写字母集[A-Z],分别为数字[00-09]、[10-35]和[36-62]

每个字母或数字必须生成两位数字,如果字母为“y”,则数字为“61”或字母为“C”,则数字为“12”,或数字为“6”,则数字为“06”

例如:

字母数字字符串:“yc69CJjVvf”


数字:61380609121945315841

按字符遍历字符串,如果字符是符号转换为数字字符串,如果字符是数字而不是格式(“0%d”),将结果累加为一个字符串,然后转换为数字。

创建plist,您必须手动输入数字集[0-9]、大写字母集[A-Z]和小写字母集[A-Z]的数据

见下图

为循环创建一个,在循环中你必须传递alpha-bate值,你将得到相应的数字

    NSString *path = [[NSBundle mainBundle] pathForResource:
                      @"YourPlistName" ofType:@"plist"];

    NSMutableArray *arrData = [[NSMutableArray alloc] initWithContentsOfFile:path];
    NSMutableArray *arrCode=[arrData valueForKey:@"code"];
    NSMutableArray *arrname=[arrData valueForKey:@"name"];
        NSString *code = [[NSString alloc] init];


    for (int i=0;i<[arrname count];i++)
    {

        if ([[arrname objectAtIndex:i] isEqualToString:StrAplahbates])//StrAplahbates is the string for which you want number value.
        {
            [code appendFormat:@"%@",arrCode [i]];



        }
    }
NSString*path=[[NSBundle mainBundle]路径用于资源:
@类型为“@“plist”]”的“YourPlistName”;
NSMutableArray*arrData=[[NSMutableArray alloc]initWithContentsOfFile:path];
NSMUTABLEARRY*arrCode=[arrData valueForKey:@“code]”;
NSMUTABLEARRY*arrname=[arrData valueForKey:@“name]”;
NSString*代码=[[NSString alloc]init];

对于(int i=0;i您可以使用Character->Number和Number->Character创建NSMutableDictionary,然后您可以遍历字符串并转换字符串, 例如:

NSMutableDictionary *stringToNumbersDictionary = [[NSMutableDictionary alloc] init];
NSMutableDictionary *numberToStringDIctionary = [[NSMutableDictionary alloc] init];
for(int i = 0;i <= 9; i++) {
    NSString *keyWithZero = [NSString stringWithFormat:@"0%d",i];
    NSString *keyWithoutZero = [NSString stringWithFormat:@"%d",i];

    // So you can look up with 06 and 6 to get the number-string
    [stringToNumbersDictionary setObject:keyWithZero forKey:keyWithoutZero];
    [numberToStringDIctionary setObject:keyWithoutZero forKey:keyWithZero];
}

// from ASCII A to ASCII Z
for(int i = 65;i <= 90;i++) {
    NSString *key = [NSString stringWithFormat:@"%c",i];
    NSString *numberKey = [NSString stringWithFormat:@"%d",i];

    [stringToNumbersDictionary setObject:numberKey forKey:key];
    [numberToStringDIctionary setObject:key forKey:numberKey];
}

// from ASCII a to ASCII z
for(int i = 97;i <= 122;i++) {
    NSString *key = [NSString stringWithFormat:@"%c",i];
    NSString *numberKey = [NSString stringWithFormat:@"%d",i];

    [stringToNumbersDictionary setObject:numberKey forKey:key];
    [numberToStringDIctionary setObject:key forKey:numberKey];
}
NSMutableDictionary*stringToNumbersDictionary=[[NSMutableDictionary alloc]init];
NSMutableDictionary*numberToStringDIctionary=[[NSMutableDictionary alloc]init];

对于(int i=0;我尝试了数字的格式(0%d),但它也会在数字中添加“S”…例如,数字是“1”,然后它会给出“01S”,但我只想要“01”。对不起,这是我的错误…这对数字[0-9]非常有效…谢谢,但是关于字母呢?制作一些字母及其代码的表格,或者制作数组并获取索引,然后添加delta(例如A的idx=0而不是code=idx+detla,其中delta=10)@ParthPatel Happy coding。
- (NSString *)numberStringWithString:(NSString *)string {
    NSMutableString *result = [[NSMutableString alloc] init];
    for(NSInteger index = 0;index < string.length;index++) {
        unichar c = [string characterAtIndex:index];
        NSString *key = [NSString stringWithFormat:@"%c",c];
        [result appendString:stringToNumbersDictionary[key]];
    }
    return result;
}
- (NSString *)stringWithNumberString:(NSString *)numberString {
    NSMutableString *result = [[NSMutableString alloc] init];
    for(NSInteger index = 0;index < numberString.length;index+=2) {
        NSString *key = [numberString substringWithRange:NSMakeRange(index, 2)];
        [result appendString:numberToStringDIctionary[key]];
    }
    return result;
}