I have a text file which contain five lines. I read that files and put them in lines. Like this
我有一个包含五行的文本文件。我读了那些文件并把它们排成一行。喜欢这个
char urlOfFile[100] = {0};
printf("Enter URL Of File: ");
scanf("%s", urlOfFile);
NSString *convertedString = [NSString stringWithFormat:@"%s", urlOfFile];
NSURL *url = [NSURL fileURLWithPath:convertedString];
NSString *fileContent = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSArray *allLines = [fileContent componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
for (NSString* line in allLines) {
NSLog(@"Line contains = %@", line);
}
and the file contains :
并且文件包含:
Project Description Start date Category Responsible Savings amount Currency Complexity
项目描述开始日期类别负责任的储蓄金额货币复杂性
4 Decrease production related non-categorized side costs 2013-01-01 00:00:00.000 Dairy Daisy Milks 11689.322459 EUR Hazardous
4减少与生产相关的非分类边成本2013-01-01 00:00:00.000 Dairy Daisy Milks 11689.322459 EUR危险
5 Stop using Kryptonite in production 2013-04-01 00:00:00.000 Dairy Clark Kent NULL NULL Moderate
5停止在生产中使用Kryptonite 2013-04-01 00:00:00.000 Dairy Clark Kent NULL NULL中等
6 Black and white logo paper 2012-06-01 00:00:00.000 Office supplies Clark Kent 4880.199567 EUR Simple
6黑白标志纸2012-06-01 00:00:00.000办公用品Clark Kent 4880.199567 EUR简单
6 Black and white logo paper 2012-06-01 00:00:00.000 Office supplies Clark Kent 4880.199567 EUR Simple
6黑白标志纸2012-06-01 00:00:00.000办公用品Clark Kent 4880.199567 EUR简单
How to sort these lines with respect to given dates in the column of start date, with ascending and descending order and display only one line if the argument is project number. Any help or clue will be highly appreciated.
如何根据开始日期列中的给定日期对这些行进行排序,按升序和降序排序,如果参数为项目编号,则只显示一行。任何帮助或线索将受到高度赞赏。
1 个解决方案
#1
1
I'm betting your data is TAB-delimited (* displays tabs as individual spaces).
我打赌你的数据是TAB分隔的(*将标签显示为单独的空格)。
So...
所以...
NSString *fileContent = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSArray *allLines = [fileContent componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
for (NSString* line in allLines) {
NSLog(@"Line contains = %@", line);
// split each tab-delimited line into fields
NSArray *allFields = [line componentsSeparatedByString:@"\t"];
// store the fields in an array of custom class, or core-data, or whatever
[theData addObject:[MyClass initWithArray:allFields]];
}
Then you can sort on the date or whatever other field / criteria you want.
然后,您可以对日期或您想要的任何其他字段/标准进行排序。
#1
1
I'm betting your data is TAB-delimited (* displays tabs as individual spaces).
我打赌你的数据是TAB分隔的(*将标签显示为单独的空格)。
So...
所以...
NSString *fileContent = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSArray *allLines = [fileContent componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
for (NSString* line in allLines) {
NSLog(@"Line contains = %@", line);
// split each tab-delimited line into fields
NSArray *allFields = [line componentsSeparatedByString:@"\t"];
// store the fields in an array of custom class, or core-data, or whatever
[theData addObject:[MyClass initWithArray:allFields]];
}
Then you can sort on the date or whatever other field / criteria you want.
然后,您可以对日期或您想要的任何其他字段/标准进行排序。