Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (NSString *)urlEncode {
- NSMutableString *output = [NSMutableString string];
- const unsigned char *source = (const unsigned char *)[self UTF8String];
- int sourceLen = strlen((const char *)source);
- for (int i = 0; i < sourceLen; ++i) {
- const unsigned char thisChar = source[i];
- // if (thisChar == ' '){
- // [output appendString:@"+"];
- if (thisChar == ' '){
- [output appendString:@"%20"];
- } else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' ||
- (thisChar >= 'a' && thisChar <= 'z') ||
- (thisChar >= 'A' && thisChar <= 'Z') ||
- (thisChar >= '0' && thisChar <= '9')) {
- [output appendFormat:@"%c", thisChar];
- } else {
- [output appendFormat:@"%%%02X", thisChar];
- }
- }
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment