-2

我有一个大约 10.000 行的 .csv 文件。现在我有一个文本字段,用户在其中输入值而不是单击按钮。现在这个值应该在 .csv 中搜索,然后在这个 Linie 中所有值都应该显示在标签中

例如

.csv:

PLZ, 名称, 代码 47158, Neuss, DE005116 46356, Moers, DE006151

视图控制器:

文本字段搜索:47158 标签1:Neuss 标签2:DE005116

感谢您的帮助

4

2 回答 2

2

1 谷歌搜索会让你开心 ;)

http://www.macresearch.org/cocoa-scientists-part-xxvi-parsing-csv-data

编辑在下面回答您的问题。

while ([scanner scanFloat:&myVariable] && [scanner scanFloat:&myVariable2] && [scanner scanFloat:&myVariable3]) {
   [NSMutableDictionary dictionaryWithObjectsAndKeys:
                [NSNumber numberWithFloat:myVariable], @"theKeyInTheCSV",
                [NSNumber numberWithFloat:myVariable2], @"theKeyInTheCSV2",
                [NSNumber numberWithFloat:myVariable3], @"theKeyInTheCSV3",
                nil]];
}
于 2012-10-14T16:44:35.700 回答
0

她是我的代码:

-(IBAction)Zollamtsname:(id)sender{


    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Zollämter Access" ofType:@"csv"];
    NSString *myText = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil ];
    NSLog(@"%@", [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]);
    if ( nil == mytext ) return NO;
    NSScanner *scanner = [NSScanner scannerWithString:myText];
    [scanner setCharactersToBeSkipped:
     [NSCharacterSet characterSetWithCharactersInString:@"\n, "]];
    NSMutableArray *newPoints = [NSMutableArray array];
    float test1, test2;
    while ( [scanner scanFloat:&test1] && [scanner scanFloat:&test2] ) {
        [newPoints addObject:
         [NSMutableDictionary dictionaryWithObjectsAndKeys:
          [NSNumber numberWithFloat:test1], @"test1",
          [NSNumber numberWithFloat:test2], @"test2",
          nil]];
    }
    [self setPoints:newPoints];
    return YES;
}




//[self.Zollamzsnummer setText:@"test"];

}

我得到 4 个错误,我不知道如何解决它们 :( 1."return NO" = void 方法不应返回值 2."return YES" = void 方法不应返回值 3. [self setPoints:newPoints]; = 不可见 @interface for 'ViewController_suche' 声明选择器 setPoints

我说 serach 值在文本字段中的是谁?

于 2012-10-15T15:10:36.473 回答