iOS從文本文件中讀取內容到字符串里
來源:易賢網 閱讀:1153 次 日期:2015-01-22 09:56:09
溫馨提示:易賢網小編為您整理了“iOS從文本文件中讀取內容到字符串里”,方便廣大網友查閱!

NSError *error;

NSString *textFileContents = [NSString

stringWithContentsOfFile:[[NSBundle mainBundle]

pathForResource:@”myTextFile”

ofType:@”txt”]

encoding:NSUTF8StringEncoding

error: & error];

// If there are no results, something went wrong

if (textFileContents == nil) {

// an error occurred

NSLog(@”Error reading text file. %@”, [error localizedFailureReason]);

}

NSArray *lines = [textFileContents componentsSeparatedByString:@” ”];

NSLog(@”Number of lines in the file:%d”, [lines count] );

更多信息請查看IT技術專欄

更多信息請查看技術文章
關于我們 | 聯(lián)系我們 | 人才招聘 | 網站聲明 | 網站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點

版權所有:易賢網