我有一个大约10,000行的.csv文件。 现在我有一个文本字段,其中用户键入的值比他单击按钮上的值。 现在这个值应该在.csv中搜索然后在这个Linie中所有值都应该显示在标签中
E.g。
.csv:
PLZ,Name,Code 47158,Neuss,DE005116 46356,Moers,DE006151
ViewControler:
文本字段搜索:47158 Label1:诺伊斯 标签2:DE005116
感谢您的帮助
答案 0 :(得分:2)
1 google搜索会让你开心;)
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]];
}
答案 1 :(得分: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。“返回NO”= void方法不应返回值 2.“return YES”= void方法不应返回值 3. [self setPoints:newPoints]; =不可见@interface for'ViewController_suche'declares选择器setPoints
我说serach值是在文本字段中吗?