问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/11218318/reading-file-line-by-line-in-ios-sdk