[英]writeToFile and encoding (objective-c)
here is my code, i try to load a html file to an string variable then write it to a html file on computer again, but the problem is that when it export the file and i open the html file by browser it shows me the html content file unexpectedly! 这是我的代码,我尝试将一个html文件加载到一个字符串变量,然后再将它写入计算机上的html文件,但问题是,当它导出文件时,我通过浏览器打开html文件,它显示我的HTML内容文件意外!
NSURL *url=[NSURL URLWithString:@"http://www.google.com"];
NSString *web=[[NSString alloc]initWithContentsOfURL:url];
[web writeToFile:@"/saleh/index.html" atomically:YES encoding:***NSUTF32BigEndianStringEncoding*** error:&theError];
as i think here is the problem encoding, isn't it? 我认为这里是编码问题,不是吗?
Yes, it is problem of encoding, use NSUTF8StringEncoding
是的,这是编码问题,使用
NSUTF8StringEncoding
NSURL *theURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@", @"http://www.google.com"]];
NSString *web=[[NSString alloc]initWithContentsOfURL:theURL];
[web writeToFile:@"path/gp.html" atomically:YES encoding: NSUTF8StringEncoding error:&error];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.