Slice a .txt file in lines
Slice a .txt file in lines
- Subject: Slice a .txt file in lines
- From: Neto <email@hidden>
- Date: Tue, 20 Jun 2006 02:44:23 -0300
Hi all,
Another newbie question...
I need to import a .txt file to my app.
Each line of the .txt must be assigned to a key of an array.
With my little knowledge and some Google, I managed to do this:
-(IBAction)importFileMethod:(id)sender
{
NSString *path = @"/Users/neto/Desktop/import.txt";
NSError *error;
NSString *stringFromFileAtPath = [[NSString alloc]
initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
NSString *cN, *sN; //(and so on - an NSString for each key)
MyArray *newItem = [[MyArray alloc] init];
cN=[stringFromFileAtPath substringWithRange: NSMakeRange(3,19)];
sN=[stringFromFileAtPath substringWithRange: NSMakeRange(20,25)];
[newItem setValue:cN forKey:@"keyOne"];
[newItem setValue:sN forKey:@"keyTwo"];
[arrayController addObject:newItem];
[newItem release];
}
The Problem: I can't use NSMakeRange(x,y) because in the
different .txt files the lengths will vary. So I need a method that
detects the beginning and the end of each line (each line ends with
an Enter)
Any ideas?
Thanks again!
Neto
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden