我想找到一个特定的单词并阅读相应的两行。
前任 :
苹果
xxxxxxxxxxxxxxxxxx
yyyyyyyyyyyyyyyyyy
三星
qqqqqqqqqqqqqqqq
wwwwwwwwwwwwwwww
诺基亚
tttttttttttttttt
zzzzzzzzzzzzzzzzz
如果我搜索“apple”,我想得到apple
第二行也是 ( yyyyyyyy
) 。我尝试使用下面的代码,但它不起作用:
NSString *contentString = [NSString stringWithContentOfFile:path/to/your/file.txt encoding:textEncoding error:&error];
if (!error) {
NSRange range = [contentString rangeOfString:yourKeyword];
......