美文网首页
利用UIDocumentInteractionControlle

利用UIDocumentInteractionControlle

作者: SunWT | 来源:发表于2018-02-26 10:29 被阅读21次

/**

  • txtg格式乱码问题解决方法

*/

- (NSString *)examineTheFilePathStr:(NSString *)str{
     NSStringEncoding *useEncodeing = nil;     //带编码头的如utf-8等,这里会识别出来
     NSString *body = [NSString stringWithContentsOfFile:str usedEncoding:useEncodeing error:nil];     //识别不到,按GBK编码再解码一次.这里不能先按GB18030解码,否则会出现整个文档无换行bug
     if (!body) {         body = [NSString stringWithContentsOfFile:str encoding:0x80000632 error:nil];     }     //还是识别不到,按GB18030编码再解码一次.
     if (!body) {         body = [NSString stringWithContentsOfFile:str encoding:0x80000631 error:nil];     }     //有值代表需要转换  为空表示不需要转换
     return body;
 }
 - (void)transformEncodingFromFilePath:(NSString *)filePath{     //调用上述转码方法获取正常字符串
     NSString *body = [self examineTheFilePathStr:filePath];     //转换为二进制
     NSData *data = [body dataUsingEncoding:NSUTF16StringEncoding];     //覆盖原来的文件
     [data writeToFile:filePath atomically:YES];     //此时在读取该文件,就是正常格式啦
 }

参考链接:http://blog.163.com/lxl_dml/blog/static/260531031201662915715785/

相关文章

  • 利用UIDocumentInteractionControlle

    /** txtg格式乱码问题解决方法 */ 参考链接:http://blog.163.com/lxl_dml/bl...

  • 使用UIDocumentInteractionControlle

    背景一: 在app中需要打开类似于 word pdf ppt 等等文件 做一个预览背景二: 所有文件都是进行的本...

  • 通过UIDocumentInteractionControlle

    前言 朋友分享推荐给我一本PDF格式的史蒂夫•乔布斯传,阅读了几篇,很受感触,于是想把他分享给大家欣赏阅读。早起闲...

  • 使用UIDocumentInteractionControlle

    引言:iOS对浏览文件提供了方便的SDK,让开发者调用实现各自的需求,之前利用UIWebView直接加载本地或者网...

  • 使用UIDocumentInteractionControlle

    这次做的项目中需要分享图片到Instagram,于是看了下Instagram的官方文档,要分享图片到Instagr...

  • 关于UIDocumentInteractionControlle

    关于UIDocumentInteractionController     UIDocumentInteracti...

  • 利用与被利用

    今天看了一个视频,复旦的教授说“朋友无功利之用”。她大概的意思是说“你之所以交朋友,并不是因为朋友有用。我们之...

  • 利用与被利用

    愚拙的,不屑去骗,也甘于被骗;机灵的,不甘被利用,也时常去骗。“骗”,不止于欺骗,也有获取信息,掠夺物品。 身边就...

  • Selenium自动化

    定位元素 利用ID定位 利用tag name定位 利用link text定位 利用class name定位 利用n...

  • 利用

    被利用,说明你还有可用之处。 人是社群动物,人和人都是相互依存的。所谓的商业文明,说到底是因交换而存在而繁盛。交换...

网友评论

      本文标题:利用UIDocumentInteractionControlle

      本文链接:https://www.haomeiwen.com/subject/atsexftx.html