Creates a copy of a string, replacing certain characters with the equivalent percent escape sequence based on the specified encoding.
- iOS 2.0–9.0Deprecated
- macOS 10.0–10.11Deprecated
- Mac Catalyst 13.0–13.0Deprecated
- tvOS 9.0–9.0Deprecated
- watchOS 2.0–2.0Deprecated
- Core Foundation
The allocator to use to allocate memory for the new
kto use the current default allocator.
CFStringobject to copy.
Characters whose percent escape sequences you want to leave intact. Pass
NULLto specify that all illegal characters be escaped.
Legal characters to be escaped. Pass
NULLto specify that no legal characters be replaced.
The encoding to use for the translation. If you are uncertain of the correct encoding, you should use UTF-8 (
CFString), which is the encoding designated by RFC 2396 as the correct encoding for use in URLs.
Built In Encodings .UTF8
A copy of
original replacing certain characters. If it does not need to be modified (no percent escape sequences are missing), this function may merely return
original with its reference count incremented. Ownership follows the create rule. See The Create Rule.
The characters escaped are all characters that are not legal URL characters (based on RFC 2396), plus any characters in
legal, less any characters in
characters. To simply correct any non-URL characters in an otherwise correct URL string, pass
NULL for the
legal parameters, and
CFString as the
It may be difficult to use this function to "clean up" unescaped or partially escaped URL strings where sequences are unpredictable and you cannot specify
characters. Instead, you can "pre-process" a URL string using
CFURLCreate then add the escape characters using
CFURLCreate, as shown in the following code fragment.