@@ -3,7 +3,7 @@ title: Bicep functions - string
3
3
description : Describes the functions to use in a Bicep file to work with strings.
4
4
ms.topic : reference
5
5
ms.custom : devx-track-bicep
6
- ms.date : 02/14 /2025
6
+ ms.date : 06/19 /2025
7
7
---
8
8
9
9
# String functions for Bicep
@@ -139,6 +139,74 @@ The output from the preceding example with the default values is:
139
139
| toStringOutput | String | one, two, three |
140
140
| toJsonOutput | Object | {"one": "a", "two": "b"} |
141
141
142
+ ## buildUri
143
+
144
+ ` buildUri(uriComponent) `
145
+
146
+ Constructs a URI by combining the provided scheme, host, port, path, and query component object into a single URI string. To parse a URI, see [ parseUri] ( #parseuri ) .
147
+
148
+ Namespace: [ sys] ( bicep-functions.md#namespaces-for-functions ) .
149
+
150
+ ### Parameters
151
+
152
+ | Parameter | Required | Type | Description |
153
+ | :--- | :--- | :--- | :--- |
154
+ | scheme | Yes | String | The protocol of the URI (e.g., ` http ` , ` https ` , ` ftp ` ). |
155
+ | host | Yes | String | The domain or hostname (e.g., ` example.com ` ). |
156
+ | port | No | Int or Null | The port number (e.g., ` 443 ` ). If not specified, defaults to ` null ` , which means the default port for the scheme is used. |
157
+ | path | Yes | String | The path component (e.g., ` /path/to/resource ` ). |
158
+ | query | No | String | The query string, including the leading ` ? ` if present (e.g., ` ?key=value ` ). Defaults to an empty string if not provided. |
159
+
160
+ ### Return Value
161
+
162
+ A string representing the absolute URI constructed from the provided components.
163
+
164
+ ### Examples
165
+
166
+ The following example shows how to use ` buildUri ` to construct a URI from individual components:
167
+
168
+ ``` bicep
169
+ param uriComponents object = {
170
+ scheme: 'https'
171
+ host: 'mystorage.blob.core.windows.net'
172
+ port: 8080
173
+ path: '/templates/nestedTemplate.json'
174
+ query: '?st=2025-05-09'
175
+ }
176
+
177
+ output constructedUri string = buildUri((uriComponents))
178
+ ```
179
+
180
+ The output from the preceding example is:
181
+
182
+ | Name | Type | Value |
183
+ | ---- | ---- | ----- |
184
+ | constructedUri | String | ` https://mystorage.blob.core.windows.net:8080/templates/nestedTemplate.json?st=2025-05-09 ` |
185
+
186
+ The following example shows how to use ` parseUri ` to extract components from an existing URI, modify them, and then use ` buildUri ` to reconstruct a new URI:
187
+
188
+ ``` bicep
189
+ param uriComponents object = parseUri('https://mystorage.blob.core.windows.net:8080/templates/nestedTemplate.json?st=2025-05-09')
190
+ param newQuery string = 'st-2025-06-19'
191
+
192
+ var updatedUriComponents object = {
193
+ scheme: uriComponents.schema
194
+ host: uriComponents.host
195
+ port: uriComponents.port
196
+ path: uriComponents.path
197
+ query: newQuery
198
+ }
199
+
200
+ // Reconstruct the URI using buildUri
201
+ output reconstructedUri string = buildUri(updatedUriComponents)
202
+ ```
203
+
204
+ The output from the preceding example is:
205
+
206
+ | Name | Type | Value |
207
+ | ---- | ---- | ----- |
208
+ | reconstrcutedUri | String | ` https://mystorage.blob.core.windows.net/newdata/newfile.json?newParam=value ` |
209
+
142
210
## concat
143
211
144
212
` concat(arg1, arg2, arg3, ...) `
@@ -894,6 +962,80 @@ The output from the preceding example with the default values is:
894
962
| ---- | ---- | ----- |
895
963
| stringOutput | String | 0000000123 |
896
964
965
+ ## parseUri
966
+
967
+ ` parseUri(uriString) `
968
+
969
+ Parses a URI string into its constituent components, such as scheme, host, port, path, and query. To build a URI string, see [ buildUri] ( #builduri ) .
970
+
971
+ Namespace: [ sys] ( bicep-functions.md#namespaces-for-functions ) .
972
+
973
+ ### Parameters
974
+
975
+ | Parameter | Required | Type | Description |
976
+ | :--- | :--- | :--- | :--- |
977
+ | uriString | Yes | string | The URI string to parse. Must be a valid URI as per RFC 3986. |
978
+
979
+ ### Return Value
980
+
981
+ An object containing the parsed URI components with the following properties:
982
+
983
+ | Property | Type | Description |
984
+ | :--- | :--- | :--- |
985
+ | scheme | String | The protocol of the URI (e.g., ` http ` , ` https ` , ` ftp ` ). |
986
+ | host | String | The domain or hostname (e.g., ` example.com ` ). |
987
+ | port | Int or null | The port number (e.g., ` 443 ` ), or ` null ` if not specified. |
988
+ | path | String | The path component (e.g., ` /path/to/resource ` ). |
989
+ | query | String | The query string, including the leading ` ? ` (e.g., ` ?key=value ` ), or empty string if not present. |
990
+
991
+ For complete details, the URI is parsed as specified in [ RFC 3986, section 3] ( https://tools.ietf.org/html/rfc3986#section-3 ) .
992
+
993
+ ### Examples
994
+
995
+ The following example shows how to use ` parseUri ` to extract components from a URI:
996
+
997
+ ``` bicep
998
+ param inputUri string = 'https://mystorage.blob.core.windows.net:8080/templates/nestedTemplate.json?st=2025-05-09'
999
+
1000
+ var parsedUri = parseUri(inputUri)
1001
+
1002
+ output scheme string = parsedUri.scheme
1003
+ output host string = parsedUri.host
1004
+ output port int = parsedUri.port
1005
+ output path string = parsedUri.path
1006
+ output query string = parsedUri.query
1007
+ ```
1008
+
1009
+ The output from the preceding example with the default values is:
1010
+
1011
+ | Name | Type | Value |
1012
+ | ---- | ---- | ----- |
1013
+ | scheme | String | ` https ` |
1014
+ | host | String | ` mystorage.blob.core.windows.net ` |
1015
+ | port | Int | ` 8080 ` |
1016
+ | path | String | ` /templates/nestedTemplate.json ` |
1017
+ | query | String | ` ?st=2025-05-09 ` |
1018
+
1019
+ The following example shows how to use ` parseUri ` to extract the host and scheme, then reconstruct a new URI with a different path using the ` uri ` function:
1020
+
1021
+ ``` bicep
1022
+ param originalUri string = 'https://mystorage.blob.core.windows.net/data/file.json?st=2025-05-09'
1023
+
1024
+ var parsedUri = parseUri(originalUri)
1025
+ var newPath = '/newdata/newfile.json'
1026
+ var modifiedUri = uri('${parsedUri.scheme}://${parsedUri.host}', newPath)
1027
+
1028
+ output originalHost string = parsedUri.host
1029
+ output newUri string = modifiedUri
1030
+ ```
1031
+
1032
+ The output from the preceding example is:
1033
+
1034
+ | Name | Type | Value |
1035
+ | ---- | ---- | ----- |
1036
+ | originalHost | String | ` mystorage.blob.core.windows.net ` |
1037
+ | newUri | String | ` https://mystorage.blob.core.windows.net/newdata/newfile.json ` |
1038
+
897
1039
## replace
898
1040
899
1041
` replace(originalString, oldString, newString) `
0 commit comments