【问题标题】:Checking text for an approximate match检查文本的近似匹配
【发布时间】:2012-11-21 22:46:03
【问题描述】:

我正在研究 Sqlite,并添加了一些问题和答案数据。我在文本字段中匹配该数据。当我输入正确答案时,它工作正常,但是大约正确的答案呢?我不知道该怎么做。

示例:如果我输入 CORRECT,那么如果它匹配,它就可以正常工作。但是……

如果我输入 CORRET,那么它必须显示“Answer is approximarely correct”

如何解决这个问题?谁能帮我。我正在匹配来自 Sqlite 的数据。

感谢和问候。

【问题讨论】:

    标签: iphone ios string ipad sqlite


    【解决方案1】:

    使用此代码从 coredata 中获取数据,并与文本字段数据进行比较;

    AppDelegate *appDelegate =  (AppDelegate*)[[UIApplication sharedApplication] delegate];
        NSManagedObjectContext *context = [appDelegate managedObjectContext];
        NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
        // Edit the entity name as appropriate.
        NSEntityDescription *entity = [NSEntityDescription entityForName:@"MileageTrack" inManagedObjectContext:context]; //Where MileageTrack is my coredata entity
        [fetchRequest setEntity:entity];
    
        NSMutableArray *array = [[NSMutableArray alloc] init];
        int i=0;
    
        NSError *error;
    
        NSArray *objects = [context executeFetchRequest:fetchRequest error:&error];
    
        for (MileageTrack *info1 in objects) {
    
            NSMutableDictionary *dict1 = [[NSMutableDictionary alloc] init];
            [dict1 setObject:info1.tripusage forKey:@"answer"];
    if([[dict1 objectForKey:@"answer"] isEqualToString:textfield.text])
    {
    NSLog(@"correct answer");
    
    }
    else
    {
    NSLog(@"wrong answer");
    
    }
    

    【讨论】:

      【解决方案2】:

      下面这个 sqlite 命令可以帮助你。

      [NSString stringWithFormat:"select username from tblData where name is %%@%",name];
      

      这个命令会带上你所有的数据, 喜欢, 如果你输入“正确” 它将需要 1 正确,2 正确,任何正确,正确任何。

      如果没有的话试试 %%;

      【讨论】:

      • 我能够从 Sqlite 获取数据,但我的问题是我没有得到近似答案 例如:因为你的名字是 Junaid,那么它可以工作,但如果我拼写错误,比如 Junad,所以我应该得到近似答案你能帮我吗?
      • 这可以使用通配符来解决,检查这个链接,它会帮助你。 sqlite.awardspace.info/syntax/sqlitepg03.htm
      猜你喜欢
      • 2013-01-27
      • 1970-01-01
      • 1970-01-01
      • 2015-10-28
      • 2011-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多