在 iOS SDK 中逐行读取文件 [英] Reading file line by line in iOS SDK

查看:53
本文介绍了在 iOS SDK 中逐行读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 texfile 如下:

I have a texfile as follows:

line1
line2
line3
line4
line5
 ....

我想从文件中读取两个字符串数组,以便 line1, line3, line 5,... 进入 array1line 2,第 4 行,第 6 行,... 进入 array2.数组的每个元素存储一行.

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.

推荐答案

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

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

步骤 2) 拆分字符串 ([NSString componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]] )

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

第 3 步)遍历数组并插入到您的 2 个数组中

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

这篇关于在 iOS SDK 中逐行读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆