开发者

how to get data from file.txt into an NSMutableArray

开发者 https://www.devze.com 2023-03-18 12:45 出处:网络
I have file.txt data file in my project which is in resource folder. Now i need to fetch the data from the file and load it into NSMutableArray.

I have file.txt data file in my project which is in resource folder.

Now i need to fetch the data from the file and load it into NSMutableArray.

how to approach to 开发者_开发技巧it.


First of all you need to read the file. And the you need to separate the string in components.

    NSString *fileString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"test" ofType:@"txt"] 
                                                     encoding:NSUTF8StringEncoding 
                                                        error:nil];
    NSMutableArray *stringsArray = [NSMutableArray arrayWithArray:[fileString componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];

    NSLog(@"Array:%@",[stringsArray description]);

Good luck.

0

精彩评论

暂无评论...
验证码 换一张
取 消