所以我一直在尝试对此进行测试;基本上我有一个名为 rawData.txt 的文本文件,它看起来像这样:
060315512 Name Lastname
050273616 Name LastName
我想拆分行,然后拆分每一行并检查第一部分(9位数字),但它似乎根本不起作用(我的窗口关闭)这段代码有什么问题吗?
NSString *path = [[NSBundle mainBundle] pathForResource: @"rawData" ofType:@"txt"];
if (path)
{
NSString *textFile = [NSString stringWithContentsOfFile:path];
NSArray *lines = [textFile componentsSeparatedByString:(@"\n")];
NSArray *line;
int i = 0;
while (i < [lines count])
{
line = [[lines objectAtIndex:i] componentsSeparatedByString:(@" ")];
if ([[line objectAtIndex:0] stringValue] == @"060315512")
{
idText.text = [[line objectAtIndex: 0] stringValue];
}
i++;
}
}