NSString中如果包括中文字符的话转换为NSURL得到的值为nil,在网上搜了下,用stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding可以解决,代码如下:

NSString *str = [NSString stringWithUTF8String:surl.c_str()];
    str = @"http://218.21.213.10/MobileOA/TIFF/鄂安办发45号关于下达2012年全市安全生产相对控制指标的通知1.jpg";
    str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSURL *imageUrl = [NSURL URLWithString:str];

UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:imageUrl]];

中间如果不加 str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];这一行则imageUrl为nil

包含中文字符的NSString 转换为NSURL的更多相关文章

  1. SQL判断某列中是否包含中文字符、英文字符、纯数字 (转)

    一.包含中文字符 select * from 表名 where 列名 like '%[吖-座]%' 二.包含英文字符 select * from 表名 where 列名 like '%[a-z]%' ...

  2. mysql查询某一个字段是否包含中文字符

    在使用mysql时候,某些字段会存储中文字符,或是包含中文字符的串,查询出来的方法是: SELECT col FROM table WHERE length(col)!=char_length(col ...

  3. SQL判断某列中是否包含中文字符或者英文字符

    SQL判断某列中是否包含中文字符或者英文字符   [sql]  select * from 表名 where 某列 like '%[吖-座]%'     select * from 表名 where ...

  4. java算法面试题:有一个字符串,其中包含中文字符、英文字符和数字字符,请统计和打印出各个字符的个数 按值的降序排序,如果值相同则按键值的字母顺序

    package com.swift; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; publi ...

  5. Java检查字符串是否包含中文字符

    转自:https://blog.csdn.net/zhanghan18333611647/article/details/80038629 强烈推荐一个大神的人工智能的教程:http://www.ca ...

  6. 【性能测试】:LR中解决接口请求中包含中文字符,服务器不识别的问题

    在LR中,直接写的接口请求,如果请求字段包含中文字段,服务器会不识别,这个时候就要用到lr_convert_string_encoding这个函数: 具体用法: lr_convert_string_e ...

  7. LR中解决接口请求中包含中文字符,服务器不识别的问题

    在LR中,直接写的接口请求,如果请求字段包含中文字段,服务器会不识别,这个时候就要用到lr_convert_string_encoding这个函数: 具体用法: lr_convert_string_e ...

  8. java 验证字符串是否包含中文字符

    中文的模式:"[\\u4e00-\\u9fa5]|\\\\u" 例子: private static final Pattern p = Pattern.compile(" ...

  9. webstorm中sass编译时目录或内容包含中文字符报错

    ruby版本:ruby 2.3.1p112 (2016-04-26 revision 54768) [x64-mingw32] sass版本:Sass 3.4.22 (Selective Steve) ...

随机推荐

  1. Linux下find命令用法小结

    find是个使用频率比较高的命令.常常用它在系统特定目录下,查找具有某种特征的文件. find命令的格式:find [-path……] -options [-print -exec -ok] path ...

  2. 关于NIOS ii烧写的几种方式(转)

    源:http://www.cnblogs.com/bingoo/p/3450850.html 1. 方法一:.sof和.elf全部保存在FPGA内,程序加载和运行也是在FPGA内部. 把FPGA的配置 ...

  3. 【学生成绩管理系统】 大二c语言作业

    几年前写的了,只能在命令行窗口运行,虽然比较挫,还是有一定参考价值... #include <cstdio> #include <conio.h> #include <i ...

  4. UIScrollView代理方法

    手拖拽后会调用 - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView [scrollView setContentOffset ...

  5. div定位

    1.float定位带来的问题<html> <head> <title>div浮动引发的问题</title> </head> <styl ...

  6. IE6下最小19px像素

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. PAT (Advanced Level) 1046. Shortest Distance (20)

    处理一下前缀和. #include<iostream> #include<cstring> #include<cmath> #include<algorith ...

  8. 自动获取访客QQ

    http://jerring.cn/bizqq/index.html http://www.oicqzone.com/qqjiqiao/2015072322139.html

  9. 初始化时查看combox的文本内容

    string sql = string.Format("select field_name from pt_temp_field where pt_name = '{0}' and temp ...

  10. PAT (Advanced Level) 1001. A+B Format (20)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...