redribben

how to fix

Feb 7th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. - (NSString *)urlEncode {
  2. NSMutableString *output = [NSMutableString string];
  3. const unsigned char *source = (const unsigned char *)[self UTF8String];
  4. int sourceLen = strlen((const char *)source);
  5. for (int i = 0; i < sourceLen; ++i) {
  6. const unsigned char thisChar = source[i];
  7. // if (thisChar == ' '){
  8. // [output appendString:@"+"];
  9. if (thisChar == ' '){
  10. [output appendString:@"%20"];
  11. } else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' ||
  12. (thisChar >= 'a' && thisChar <= 'z') ||
  13. (thisChar >= 'A' && thisChar <= 'Z') ||
  14. (thisChar >= '0' && thisChar <= '9')) {
  15. [output appendFormat:@"%c", thisChar];
  16. } else {
  17. [output appendFormat:@"%%%02X", thisChar];
  18. }
  19. }
  20. return output;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment