2015-04-08

Objective C urlencode urldecode

Views: 8246 | Add Comments
NSString *urlencode(NSString *str){
	CFStringEncoding cfEncoding = kCFStringEncodingUTF8;
	str = (__bridge NSString *)CFURLCreateStringByAddingPercentEscapes(
		NULL,
		(CFStringRef)str,
		NULL,
		CFSTR("!*'();:@&=+$,/?%#[]"),
		cfEncoding
		);
	return str;
}

NSString *urldecode(NSString *str){
	CFStringEncoding cfEncoding = kCFStringEncodingUTF8;
	str = (__bridge NSString *)CFURLCreateStringByReplacingPercentEscapesUsingEncoding (
		NULL,
		(CFStringRef)str,
		CFSTR(""),
		cfEncoding
		);
	return str;
}

Related posts:

  1. Objective-C 对二进制数据 NSData 进行 URL 编码
  2. iOS与PHP加密解密
  3. Objective-C 单引号中包含4个字符
  4. Xcode 如何让 Objective C 项目链接 C++ 静态库
  5. C++成员函数作为pthread_create参数
Posted by ideawu at 2015-04-08 13:14:49

Leave a Comment