Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个texfile如下:
line1 line2 line3 line4 line5 ....
我想从文件中读取两个字符串数组,以便line1, line3, line 5,...进入array1并line 2, line 4, line 6,...进入array2. 数组的每个元素存储一行。
line1, line3, line 5,...
array1
line 2, line 4, line 6,...
array2
步骤 1) 读取文件 ( [NSString stringWithContentsOfFile:encoding:error:])
[NSString stringWithContentsOfFile:encoding:error:]
步骤 2) 拆分字符串 ( [NSString componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]])
[NSString componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]]
步骤 3) 遍历数组并插入到您的 2 个数组中