Im new to iphone programming and im kinda stuck with my current project. I got a text file with a lot of data in it. Data is sorted like this:
51398030 10003254 80211593/94 1301281744 TOMTOM100
51398030 10003254 80211593/94 1301281744 TOMTOM101
51398030 10003254 80211593/94 1301281745 TOMTOM102
51398030 10003254 80211593/94 1301281745 TOMTOM103
51398033 10003254 80211595 1301281744 TOMTOM100
51398033 10003254 80211595 1301281744 TOMTOM101
51398033 10003254 80211595 1301281745 TOMTOM102
51398033 10003254 80211595 1301281745 TOMTOM103
51398029 10003254 80211597/98 1301281744 TOMTOM100
51398029 10003254 80211597/98 1301281744 TOMTOM101
51398029 10003254 80211597/98 1301281745 TOMTOM102
51398029 10003254 80211597/98 1301281745 TOMTOM103
I already imported this txt file and created a NSMutableArray that contains each line as object. Now i have a textfield where the user can enter a number. the app should now look trough the text file and and sort out the lines containing this number.
I already looked at https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Strings/Articles/Scanners.html#//apple_ref/doc/uid/20000147-BCIEFGHC
but i dont know how to start.
This is how far i got:
NSData *tmpData = [NSData dataWithContentsOfURL:[NSURL URLWithString:trackTraceFileUrlName] ];
NSLog(@"%@",trackTraceFileUrlName);
//convert data to string
NSString *tmpString = [[NSString alloc] initWithData:tmpData encoding:NSUTF8StringEncoding];
NSArray *piecesArray = [tmpString componentsSeparatedByString:@"\n"];
NSMutableArray *trackTraceContent = [NSMutableArray arrayWithArray:piecesArray];
NSLog(@"*%@*",trackTraceContent);
Since you probably want to search over all the lines in the array, and assuming that you array just contains the strings as NSString objects:
Of course, you can also create the target array without using NSPredicate, by just iterating over
stringArrayand adding the right objects to a NSMutableArrayresults.