title: URLEncoding a string with Objective-C
body: <p>I'm trying to URL encode a string to form a GET request from objective-c.</p>
  
  <pre><code>NSString *params = @"'Decoded data!'/foo.bar:baz";
  
  NSRunAlertPanel( @"Error", [params urlEncoded], @"OK", nil, nil );
  </code></pre>
  
  <p>This is the category extending NSString</p>
  
  <pre><code>    -(NSString *) urlEncoded
  {
      NSString *encoded = (NSString *)CFURLCreateStringByAddingPercentEscapes(
                                                     NULL,
                                                     (CFStringRef)self,
                                                     NULL,
                                                     (CFStringRef)@"!*'\"();:@&amp;=+$,/?%#[]% ",
                                                     kCFStringEncodingUTF8 );
      return encoded;
  }
  </code></pre>
  
  <p>So the first time I run it I get back</p>
  
  <pre><code>1606410046ecoded          1606410784ata2270.000000foo.bar0X1.001716P-1042baz
  </code></pre>
  
  <p>from the dialog box.</p>
  
  <p>Immediately after I run it again I get this</p>
  
  <pre><code>1606410046ecoded          1606410944ata227369374562920703448982951250259562309742470533728899744288431318481119278377104028261651081181287077973859930826299575521579020410425419424562236383226511593137467590082636817579938932512039895040.000000foo.bar0X1.66E6156303225P+771baz
  </code></pre>
  
  <p>Then if I run it AGAIN it goes back to the first one. It's really weird.</p>
  
  <p>If params is set to @"&amp;" or @" " I just get back a "2" (w/o the quotes) in the dialog box.</p>
  
  <p>Also is there a way I can have the % signs be shown in the alert dialog?</p>
  
  <p>Thanks</p>