objective-c中将txt转plist

在window系统下,用股票软件导出 2953个股 数据到 Excell 文件中,

在利用Excell文件另存为 txt 文件,内容如下:

000001 平安银行

000002 万科A

000004 国农科技

000005 世纪星源

000006 深振业A

000007 全新好

000008 神州高铁

代码:

-(void)converToPlist:(NSString*)txtName{

NSString*stocktxtPath = [[NSBundlemainBundle]pathForResource:txtNameofType:@"txt"];

//很多取不出数据的问题就是编码,有的是UTF-8,有的是GBK,我的是UTF-16对应的使用到了NSUTF16StringEncoding

NSString*stockContent = [[NSStringalloc]initWithContentsOfFile:stocktxtPathencoding:NSUTF16StringEncodingerror:nil];

NSArray*stockArrays = [stockContentcomponentsSeparatedByString:@"\r\n"];

NSString*plistPath = [NSHomeDirectory()stringByAppendingPathComponent:@"AllStock.plist"];

NSLog(@"文件保存地址:%@",plistPath);

NSMutableArray*resultsArr = [[NSMutableArrayalloc]initWithCapacity:0];

for(NSIntegerj =0; j < stockArrays.count; j++){

NSString*stockStr = [stockArraysobjectAtIndex:j];

NSArray*stockArr = [stockStrcomponentsSeparatedByString:@"\t"];

[resultsArraddObject:@{@"Code":[stockArrobjectAtIndex:0],@"Name":[stockArrobjectAtIndex:1]}];

}

[resultsArrwriteToFile:plistPathatomically:YES];

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • *面试心声:其实这些题本人都没怎么背,但是在上海 两周半 面了大约10家 收到差不多3个offer,总结起来就是把...
    Dove_iOS阅读 27,217评论 30 472
  • 27、ViewController的didReceiveMemoryWarning是在什么时候调用的?默认的操作是...
    烟雨平生花飞舞阅读 623评论 0 1
  • 1.OC里用到集合类是什么? 基本类型为:NSArray,NSSet以及NSDictionary 可变类型为:NS...
    轻皱眉头浅忧思阅读 1,396评论 0 3
  • NSRange : 表示范围作用的结构体,3种方式创建 // 方式一 NSRange range; locatio...
    路墨阅读 1,074评论 1 8
  • 今天就本周作业的读取txt文件查找了的一些方法,如下: //读取文本内容NSError *error;NSStri...
    霏誠拜咬o阅读 637评论 0 0