代码:
#import "EncodeURLString.h"
@implementation EncodeURLString
- (NSString *)urlEncodeValue:(NSString *)str
{
NSString *result = (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)str, NULL, CFSTR("!*'\";$,#[] "), kCFStringEncodingUTF8);
return [result autorelease];
}
- (NSString *)safeEcapeString:(NSString *)str
{
NSString *result = [str stringByReplacingOccurrencesOfString:@":" withString:@"\\:"];
result = [result stringByReplacingOccurrencesOfString:@";" withString:@"\\;"];
result = [result stringByReplacingOccurrencesOfString:@"," withString:@"\\,"];
return [result autorelease];
}
@end
此代码导致我的网址中的#标记被转换为%23有没有办法让它停止转换哈希标记?我已经尝试从这里删除它CFSTR(“!*'\”; $,#[]“)但它不起作用它仍然转换它。任何帮助或提示将不胜感激
由于
答案 0 :(得分:0)
从legalURLCharactersToBeEscaped
参数中删除哈希,并使用CFSTR("#")
charactersToLeaveUnescaped
。