- (NSString *)urlencode {
NSString *encUrl = [self stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
int len = [encUrl length];
const char *c;
c = [encUrl UTF8String];
NSString *ret = @"";
for(int i = 0; i < len; i++) {
switch (*c) {
case '/':
ret = [ret stringByAppendingString:@"%2F"];
break;
case '\'':
ret = [ret stringByAppendingString:@"%27"];
break;
case ';':
ret = [ret stringByAppendingString:@"%3B"];
break;
case '?':
ret = [ret stringByAppendingString:@"%3F"];
break;
case ':':
ret = [ret stringByAppendingString:@"%3A"];
break;
case '@':
ret = [ret stringByAppendingString:@"%40"];
break;
case '&':
ret = [ret stringByAppendingString:@"%26"];
break;
case '=':
ret = [ret stringByAppendingString:@"%3D"];
break;
case '+':
ret = [ret stringByAppendingString:@"%2B"];
break;
case '$':
ret = [ret stringByAppendingString:@"%24"];
break;
case ',':
ret = [ret stringByAppendingString:@"%2C"];
break;
case '[':
ret = [ret stringByAppendingString:@"%5B"];
break;
case ']':
ret = [ret stringByAppendingString:@"%5D"];
break;
case '#':
ret = [ret stringByAppendingString:@"%23"];
break;
case '!':
ret = [ret stringByAppendingString:@"%21"];
break;
case '(':
ret = [ret stringByAppendingString:@"%28"];
break;
case ')':
ret = [ret stringByAppendingString:@"%29"];
break;
case '*':
ret = [ret stringByAppendingString:@"%2A"];
break;
default:
ret = [ret stringByAppendingFormat:@"%c", *c];
}
c++;
}
return ret;
}
url编码
最新推荐文章于 2023-07-24 20:44:46 发布