将字数行改为数字目标c

时间:2014-10-17 10:54:21

标签: objective-c nsarray

您好我是一名Objective C初学者,只是玩了一个我从开发人员那里尝试将一行字数(二百三十二)改为数字(232)的代码。我设法得到一个单词来改变另一个数字,但我无法弄清楚如何将单词与空白联系起来。二十岁变成了二十岁而二十二岁则没有任何回报。请问有关该怎么做?

    //text recognition
    NSArray *values = [[NSArray alloc]initWithObjects: @"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",nil];
    NSArray *keys = [[NSArray     alloc]initWithObjects: @"zero",@"one",@"two",@"three",@"four",@"five",@"six",@"seven",@"eight",@"nine"    , nil];
    numbers = [[NSDictionary alloc]initWithObjects:values forKeys:keys];

    //PASSED TEXT
    for (NSExtensionItem *item in self.extensionContext.inputItems) {
    for (NSItemProvider *itemProvider in item.attachments) {
    //NSLog(@"%@",itemProvider);
    if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypePropertyList]) {           
   //Safari
    __weak ActionViewController *sself = self;
   [itemProvider loadItemForTypeIdentifier: (NSString *) kUTTypePropertyList options: 0
    completionHandler: ^(id<NSSecureCoding> item, NSError *error) {
    if (item != nil) {
    NSDictionary *resultDict = (NSDictionary *) item;
    sself.jsString = resultDict[NSExtensionJavaScriptPreprocessingResultsKey][@"selection"];

    //update UI
    //.........I have cut some code out

    -(void)selection{
    //text recognition
    if ([self.jsString isEqualToString:@""]) {
        [_calculations setText:@"0"];
    } else {
        for (NSString *key in numbers) {
                [_calculations setText:self.jsString];
            if( [self.jsString caseInsensitiveCompare:key] == NSOrderedSame) {
                [_calculations setText:[numbers objectForKey:key]];
                break;
            }
        }
    }

0 个答案:

没有答案