DavidNg
DavidNg

Reputation: 2836

Reading file line by line in iOS SDK

I have a texfile as follows:

line1
line2
line3
line4
line5
 ....

I want to read from file into two arrays of string so that line1, line3, line 5,... go into array1 and line 2, line 4, line 6,... go into array2. Each element of arrays stores one line.

Upvotes: 3

Views: 9110

Answers (1)

borrrden
borrrden

Reputation: 33421

Step 1) Read file ([NSString stringWithContentsOfFile:encoding:error:] )

Step 2) Split string ([NSString componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] )

Step 3) Iterate over array and insert into your 2 arrays

Upvotes: 5

Related Questions