首页 > 网站 > 建站经验 > 正文

iOS从文本文件中读、取内容到字符串里

2019-11-02 14:23:01
字体:
来源:转载
供稿:网友

   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:@” ”];

  NSL

骂人的话[www.62-6.com/1/marenbaodian/]
og(@”Number of lines in the file:%d”, [lines count] );

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表