• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Slice a .txt file in lines
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: Slice a .txt file in lines
      • From: Ben Lachman <email@hidden>
  • Prev by Date: Is it a bug in NSAffineTransform?
  • Next by Date: Re: Slice a .txt file in lines
  • Previous by thread: Re: Is it a bug in NSAffineTransform?
  • Next by thread: Re: Slice a .txt file in lines
  • Index(es):
    • Date
    • Thread