- #import <Foundation/Foundation.h>
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
- //自定义创建字符串,可以读取文件中的使用NSString *nameString=[NSString stringWithContentsOfFile:];
- NSString *nameString=@"sadasdasgagg";
- //将字符串按"\n"进行分割,并保存在数组中
- NSArray *names=[nameString componentsSeparatedByString:@"\n"];
- //枚举数组,一次处理一个字符串
- for (NSString *n in names) {
- //查找字符串(单词)"string",忽略大小写
- NSRange r=[n rangeOfString:@"string"options:NSCaseInsensitiveSearch];
- //是否找到
- if (r.location!=NSNotFound) {
- NSLog(@"%@",n);
- }
- }
- }
- return 0;
- }
复制代码 |
|