Uri.EscapeDataString
URIPercent-encodes special characters in a text value for safe use in a URI.
Syntax
Uri.EscapeDataString(data as text) as textParameters
| Name | Type | Required | Description |
|---|---|---|---|
data | text | Yes | The text value to percent-encode. |
Return Value
text — The percent-encoded text value.
Remarks
Uri.EscapeDataString applies percent-encoding to a text value, replacing characters that are not allowed in URI components (spaces, ampersands, slashes, etc.) with their %XX hex equivalents. For example, a space becomes %20, and & becomes %26.
This is useful when embedding dynamic values directly into URL path segments or query parameters where Uri.BuildQueryString is not appropriate (e.g., in path segments):
``powerquery
let
ItemName = "Widget A/B",
Url = "https://api.example.com/items/" & Uri.EscapeDataString(ItemName)
in
Url
// Result: "https://api.example.com/items/Widget%20A%2FB"
``
Note: Uri.BuildQueryString already encodes values automatically, so you do not need to call Uri.EscapeDataString on values passed to Uri.BuildQueryString.
Examples
Example 1: Encode special characters for a URL
let
Values = {"Hello World", "A&B=C", "path/to/file", "100% done"},
Encoded = List.Transform(Values, each Uri.EscapeDataString(_)),
Rows = List.Transform({0..List.Count(Values)-1}, each {Values{_}, Encoded{_}})
in
#table({"Original", "Encoded"}, Rows)Original | Encoded | |
|---|---|---|
| 1 | Hello World | Hello%20World |
| 2 | A&B=C | A%26B%3DC |
| 3 | path/to/file | path%2Fto%2Ffile |
| 4 | 100% done | 100%25%20done |