码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 编码转换

时间:2015-09-01 12:11:56      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

- (NSString *)SaveFileToDocuments:(NSString *)url

{

    // NSString *url = @"http://172.28.250.70/ad/20140210151602.jpg";

    NSString *FileName = [url lastPathComponent];

    NSString *resultFilePath = @"";

    if (url.length > 7) {

        

        NSString *destFolderPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:@"IadImages"];

        NSString *destFilePath = [destFolderPath stringByAppendingPathComponent:url];

        if (! [[NSFileManager defaultManager] fileExistsAtPath:destFolderPath]) { //判断文件夹是否存在

            

            [[NSFileManagerdefaultManager] createDirectoryAtPath:destFolderPath withIntermediateDirectories:YESattributes:nilerror:nil];

        }

        

        

        if ([[NSFileManager defaultManager] fileExistsAtPath:destFilePath]) { //判断文件是否存在

            

            resultFilePath = destFilePath;

        } else {

            

            NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];

            if ([imageData writeToFile:destFilePath atomically:YES]) {

                resultFilePath = destFilePath;

            }

            else {

                resultFilePath = destFilePath;

            }

        }

    }

    return resultFilePath;

}

 

- (NSString*)UTF8_To_GB2312:(NSString*)utf8string

{

    NSStringEncoding encoding =CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);

    NSData* gb2312data = [utf8string dataUsingEncoding:encoding];

    

    return [[NSString alloc] initWithData:gb2312data encoding:encoding];

}

 

iOS 编码转换

标签:

原文地址:http://www.cnblogs.com/yyzanll/p/4775111.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!