Uri.EscapeComponent(String) Uri.EscapeComponent(String) Uri.EscapeComponent(String) Uri.EscapeComponent(String) Uri.EscapeComponent(String) Method


Converts a Uniform Resource Identifier (URI) string to its escaped representation.

public : static Platform::String EscapeComponent(Platform::String toEscape)
static winrt::hstring EscapeComponent(winrt::hstring toEscape) const;
public static string EscapeComponent(String toEscape)
Public Shared Function EscapeComponent(toEscape As String) As string
var string = Windows.Foundation.Uri.escapeComponent(toEscape);


String String String

The string to convert.


string string string

The escaped representation of toEscape.


Use EscapeComponent as a utility to escape any Uniform Resource Identifier (URI) component that requires escaping in order to construct a valid Uri object. For example, if your app is using a user-provided string and adding it to a query that is sent to a service, you may need to escape that string in the Uniform Resource Identifier (URI) because the string might contain characters that are invalid in a Uniform Resource Identifier (URI). This includes characters as simple as spaces; even input that seems to be pure ASCII may still need encoding to be valid as a component of a Uniform Resource Identifier (URI).

You can append the string you get from EscapeComponent onto other strings before calling the Uri(String) constructor. You'll want to encode each component separately, because you do not want to escape the characters that are significant to how the Uri(String) constructor parses the string into components, such as the "/" between host and path or the "?" between path and query.

EscapeComponent might also be useful for other scenarios where a Uniform Resource Identifier (URI)-escaped string is needed for an HTTP request scenario, such as using APIs in the Windows.Web.Http namespace.

See also