views:

76

answers:

2

Code:

NSString* string3 = (NSString*)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)tvQ.text, NULL, (CFStringRef)@":/?#[]@!$&'()*+,;=", kCFStringEncodingUTF8);

My code is working to pass special characters properly via URL to my database, however, if I insert data with linebreaks, it seems to break my app and crashes. Any ideas?

**code was provided to me by user "tc." from a previous question. This is a different issue, so I started a new question.

Figured out the answer:

NSString* encoded = [[string stringByReplacingOccurrencesOfString:@"\n" withString:@" "] stringByReplacingOccurrencesOfString:@"ç" withString:@"c"];
NSString* string3 = [(NSString*)CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)encoded, NULL, (CFStringRef)@":/?#[]@!$&'()*+,;=", kCFStringEncodingUTF8) autorelease];
+1  A: 

maybe you should parse the string before calling CFURLCreateStringByAddingPercentEscapes...

A good idea is probably to use NSMutableString's method

replaceOccurrencesOfString:withString:options:range:
Kostas.N
how do I use that and the CFURLCreateStringByAddingPercentEscapes in the same declaration of string3?
BigMike
A: 
  1. Inside the NSString class reference, there is a section named Working with URLs.

    • stringByAddingPercentEscapesUsingEncoding:
    • stringByReplacingPercentEscapesUsingEncoding:
  2. The parameters for url works by the form:

    param1 = value1 & param2 = value2 ....

    Your sub has no value, maybe it should be removed from the param list.

Toro
Thanks toro - just updated my post since I figured it out.
BigMike