开发者

ios stringWithContentsOfURL with encoding?

开发者 https://www.devze.com 2023-03-07 08:54 出处:网络
I have a 开发者_运维技巧problem using \"stringWithContentsOfURL\" to get source page of a web(chinese)

I have a 开发者_运维技巧problem using "stringWithContentsOfURL" to get source page of a web(chinese) Thinking using "NSUTF8StringEncoding" but didn't work(got null for result). My code looks like this

NSString *string = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.morningstar.com.tw/download_pdf_2-1.aspx"] encoding:NSUTF8StringEncoding error:nil];

NSLog(@"html = %@",string);

replaced "NSUTF8StringEncoding" by "NSASCIIStringEncoding", did get a result but words are scrambled.

Thanks for the help!


You need a different encoding:

NSStringEncoding encoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingDOSChineseTrad);

You can also use kCFStringEncodingDOSChineseSimplif for simplified chinese. Use encoding in place of NSASCIIStringEncoding or the other standard ones.

See the documentation for more encodings if these do not work properly.

0

精彩评论

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