snipt

Ctrl+h for KB shortcuts

Objective-C

iOS SDK Url encode for special characters

1
2
3
4
5
//!*'();:@&=+$,/?%#[]
- (NSString *)encodeWith:(NSString *)string
{
    return CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)string, NULL, CFSTR("!*'();:@&=+$,/?%#[]"), kCFStringEncodingUTF8));
}
https://snipt.net/embed/c45918d39b1af0c4d8b8878baf8a91ee/
/raw/c45918d39b1af0c4d8b8878baf8a91ee/
c45918d39b1af0c4d8b8878baf8a91ee
objective-c
Objective-C
5
2019-05-07T09:16:50
True
False
True
Apr 02, 2014 at 07:42 PM
/api/public/snipt/126894/
ios-sdk-url-encode-for-special-characters
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">//!*&#39;();:@&amp;=+$,/?%#[]</span> </span><span id="L-2"><a name="L-2"></a><span class="p">-</span> <span class="p">(</span><span class="bp">NSString</span> <span class="o">*</span><span class="p">)</span><span class="nf">encodeWith:</span><span class="p">(</span><span class="bp">NSString</span> <span class="o">*</span><span class="p">)</span><span class="nv">string</span> </span><span id="L-3"><a name="L-3"></a><span class="p">{</span> </span><span id="L-4"><a name="L-4"></a> <span class="k">return</span> <span class="n">CFBridgingRelease</span><span class="p">(</span><span class="n">CFURLCreateStringByAddingPercentEscapes</span><span class="p">(</span><span class="n">kCFAllocatorDefault</span><span class="p">,</span> <span class="p">(</span><span class="k">__bridge</span> <span class="n">CFStringRef</span><span class="p">)</span><span class="n">string</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="n">CFSTR</span><span class="p">(</span><span class="s">&quot;!*&#39;();:@&amp;=+$,/?%#[]&quot;</span><span class="p">),</span> <span class="n">kCFStringEncodingUTF8</span><span class="p">));</span> </span><span id="L-5"><a name="L-5"></a><span class="p">}</span> </span></pre></div> </td></tr></table>
SDK, Url, encode, iOS