UIWebView加载ANSI格式的txt文件出现乱码问题解决

    //若为txt文档
    if([encodedString hasSuffix:@".txt"]){
                
        NSData* Data = [NSData dataWithContentsOfURL:weburl];
        NSString* aStr = [[NSString alloc] initWithData:Data encoding:NSUTF8StringEncoding];
        if (!aStr) {
            aStr=[[NSString alloc] initWithData:Data encoding:0x80000632];
        }
        if (!aStr) {
            aStr=[[NSString alloc] initWithData:Data encoding:0x80000631];
        }

//        NSString* aStr = [[NSString alloc] initWithData:Data encoding:0x80000632];
        NSString* responseStr = [NSString stringWithFormat:
                                 @"<HTML>"
                                 "<head>"
                                 "<title>Text View</title>"
                                 "</head>"
                                 "<BODY>"
                                 "<pre>"
                                 "%@"
                                 "</pre>"
                                 "</BODY>"
                                 "</HTML>",
                                 aStr];
        [showPdfWebview loadHTMLString:responseStr baseURL:weburl];
        [aStr release];

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。