Windows Dev Center

Uri.EscapeComponent | escapeComponent method

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

Syntax


var string = Windows.Foundation.Uri.escapeComponent(toEscape);

Parameters

toEscape

Type: String [JavaScript] | Platform::String [C++]

The string to convert.

Return value

Type: String [JavaScript] | Platform::String [C++]

The escaped representation of toEscape.

Remarks

Use EscapeComponent as a utility to escape any 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 URI because the string might contain characters that are invalid in a 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 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 URI-escaped string is needed for an HTTP request scenario, such as using APIs in the Windows.Web.Http namespace.

Requirements (device family)

Device family

Universal

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Foundation
Windows::Foundation [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (operating system)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8

Namespace

Windows.Foundation
Windows::Foundation [C++]

Metadata

Windows.winmd

See also

Uri
Uri(String) constructor

 

 

Show:
© 2015 Microsoft