zoukankan      html  css  js  c++  java
  • [iOS开发]中文的URL Encode

    有两种方法:

    一,使用NSString的方法:

    NSString* string2 = [string1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSString* string1 = [string2 stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

     

    二、使用CFStringRef的方法

    sUrl = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)sUrl, nil, nil, kCFStringEncodingUTF8);

     

    但这两个方法,都不会处理URL中的保留字符,如果要处理保留字符,推荐使用Google的objective c 工具库 GTMNSString+URLArguments来处理:

    http://code.google.com/p/google-toolbox-for-mac/source/browse/trunk/Foundation/GTMNSDictionary%2BURLArguments.h

  • 相关阅读:
    Heroku
    Git基本命令(转)
    github之从零开发
    物理层、、。。。
    BeautifulSoup, 的使用
    路径设置
    http协议
    Python 的os模块与sys模块
    python 操作MySQL数据库
    多进程记要
  • 原文地址:https://www.cnblogs.com/liangxing/p/2549486.html
Copyright © 2011-2022 走看看