0

代码 :

#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

此代码导致我的 url 中的 # 标签被转换为 %23 有没有办法让它停止转换哈希标签?我已经尝试从这里删除它 CFSTR("!*'\";$,#[] ") 但它不起作用它仍然可以转换它。任何帮助或提示将不胜感激

谢谢

4

1 回答 1

0

legalURLCharactersToBeEscaped参数中删除哈希并使用CFSTR("#")for charactersToLeaveUnescaped

于 2012-05-06T22:37:35.600 回答