Jaa


Uri.EscapeComponent(String) Method

Definition

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 const& toEscape);
public static string EscapeComponent(string toEscape);
function escapeComponent(toEscape)
Public Shared Function EscapeComponent (toEscape As String) As String

Parameters

toEscape
String

Platform::String

winrt::hstring

The string to convert.

Returns

String

Platform::String

winrt::hstring

The escaped representation of toEscape.

Remarks

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.

Applies to

See also