Reading file line by line in iOS SDK

落爺英雄遲暮 提交于 2019-12-07 20:19:33

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!