Skip to content

Commit aac00a2

Browse files
committed
update
1 parent 9989928 commit aac00a2

File tree

1 file changed

+39
-47
lines changed

1 file changed

+39
-47
lines changed

articles/azure-resource-manager/bicep/bicep-functions-string.md

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Bicep functions - string
33
description: Describes the functions to use in a Bicep file to work with strings.
44
ms.topic: reference
55
ms.custom: devx-track-bicep
6-
ms.date: 05/09/2025
6+
ms.date: 06/19/2025
77
---
88

99
# String functions for Bicep
@@ -141,26 +141,21 @@ The output from the preceding example with the default values is:
141141

142142
## buildUri
143143

144-
`buildUri(scheme, host, path, query, fragment)`
144+
`buildUri(uriComponent)`
145145

146-
Constructs a URI by combining the provided scheme, host, path, query, and fragment components into a single URI string. To parse a URI, see [parseUri](#parseuri).
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).
147147

148148
Namespace: [sys](bicep-functions.md#namespaces-for-functions).
149149

150150
### Parameters
151151

152152
| Parameter | Required | Type | Description |
153153
|:--- |:--- |:--- |:--- |
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-
| path | Yes | string | The path component (e.g., `/path/to/resource`). |
157-
| query | No | string | The query string, including the leading `?` if present (e.g., `?key=value`). Defaults to an empty string if not provided. |
158-
| fragment | No | string | The fragment identifier, including the leading `#` if present (e.g., `#section`). Defaults to an empty string if not provided. |
159-
160-
* The `scheme`, `host`, and `path` parameters are required to ensure a valid URI structure.
161-
* The `query` and `fragment` parameters are optional and can be omitted or set to an empty string (`''`) if not needed.
162-
* The function handles proper formatting, ensuring correct separators (e.g., `://` between scheme and host, `/` for paths, `?` for queries, `#` for fragments) and avoids issues like double slashes.
163-
* For complete details, the URI is constructed as specified in [RFC 3986, section 3](https://tools.ietf.org/html/rfc3986#section-3).
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. |
164159

165160
### Return Value
166161

@@ -171,44 +166,46 @@ A string representing the absolute URI constructed from the provided components.
171166
The following example shows how to use `buildUri` to construct a URI from individual components:
172167

173168
```bicep
174-
var scheme = 'https'
175-
var host = 'mystorage.blob.core.windows.net'
176-
var path = '/templates/nestedTemplate.json'
177-
var query = '?st=2025-05-09'
178-
var fragment = '#section'
179-
180-
var constructedUri = buildUri(scheme, host, path, query, fragment)
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+
}
181176
182-
output uriOutput string = constructedUri
177+
output constructedUri string = buildUri((uriComponents))
183178
```
184179

185180
The output from the preceding example is:
186181

187182
| Name | Type | Value |
188183
| ---- | ---- | ----- |
189-
| uriOutput | String | `https://mystorage.blob.core.windows.net/templates/nestedTemplate.json?st=2025-05-09#section` |
184+
| constructedUri | String | `https://mystorage.blob.core.windows.net:8080/templates/nestedTemplate.json?st=2025-05-09` |
190185

191186
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:
192187

193188
```bicep
194-
param originalUri string = 'https://mystorage.blob.core.windows.net/data/file.json?st=2025-05-09'
195-
196-
var parsedUri = parseUri(originalUri)
197-
var newPath = '/newdata/newfile.json'
198-
var newQuery = '?newParam=value'
199-
200-
var newUri = buildUri(parsedUri.scheme, parsedUri.host, newPath, newQuery, parsedUri.fragment)
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+
}
201199
202-
output originalHost string = parsedUri.host
203-
output newUri string = newUri
200+
// Reconstruct the URI using buildUri
201+
output reconstructedUri string = buildUri(updatedUriComponents)
204202
```
205203

206204
The output from the preceding example is:
207205

208206
| Name | Type | Value |
209207
| ---- | ---- | ----- |
210-
| originalHost | String | `mystorage.blob.core.windows.net` |
211-
| newUri | String | `https://mystorage.blob.core.windows.net/newdata/newfile.json?newParam=value` |
208+
| reconstrcutedUri | String | `https://mystorage.blob.core.windows.net/newdata/newfile.json?newParam=value` |
212209

213210
## concat
214211

@@ -969,7 +966,7 @@ The output from the preceding example with the default values is:
969966

970967
`parseUri(uriString)`
971968

972-
Parses a URI string into its constituent components, such as scheme, host, path, query, and fragment. To build a URI string, see [buildUri](#builduri).
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).
973970

974971
Namespace: [sys](bicep-functions.md#namespaces-for-functions).
975972

@@ -985,14 +982,11 @@ An object containing the parsed URI components with the following properties:
985982

986983
| Property | Type | Description |
987984
|:--- |:--- |:--- |
988-
| scheme | string | The protocol of the URI (e.g., `http`, `https`, `ftp`). |
989-
| host | string | The domain or hostname (e.g., `example.com`). |
990-
| port | int or null | The port number (e.g., `443`), or `null` if not specified. |
991-
| path | string | The path component (e.g., `/path/to/resource`). |
992-
| query | string | The query string, including the leading `?` (e.g., `?key=value`), or empty string if not present. |
993-
| fragment | string | The fragment identifier, including the leading `#` (e.g., `#section`), or empty string if not present. |
994-
| authority | string | The full authority component (e.g., `example.com:443`), combining host and port if present. |
995-
| isAbsolute | bool | Indicates whether the URI is absolute (i.e., includes a scheme). |
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. |
996990

997991
For complete details, the URI is parsed as specified in [RFC 3986, section 3](https://tools.ietf.org/html/rfc3986#section-3).
998992

@@ -1001,16 +995,15 @@ For complete details, the URI is parsed as specified in [RFC 3986, section 3](ht
1001995
The following example shows how to use `parseUri` to extract components from a URI:
1002996

1003997
```bicep
1004-
param inputUri string = 'https://mystorage.blob.core.windows.net/templates/nestedTemplate.json?st=2025-05-09#section'
998+
param inputUri string = 'https://mystorage.blob.core.windows.net:8080/templates/nestedTemplate.json?st=2025-05-09'
1005999
10061000
var parsedUri = parseUri(inputUri)
10071001
10081002
output scheme string = parsedUri.scheme
10091003
output host string = parsedUri.host
1004+
output port int = parsedUri.port
10101005
output path string = parsedUri.path
10111006
output query string = parsedUri.query
1012-
output fragment string = parsedUri.fragment
1013-
output isAbsolute bool = parsedUri.isAbsolute
10141007
```
10151008

10161009
The output from the preceding example with the default values is:
@@ -1019,10 +1012,9 @@ The output from the preceding example with the default values is:
10191012
| ---- | ---- | ----- |
10201013
| scheme | String | `https` |
10211014
| host | String | `mystorage.blob.core.windows.net` |
1015+
| port | Int | `8080` |
10221016
| path | String | `/templates/nestedTemplate.json` |
10231017
| query | String | `?st=2025-05-09` |
1024-
| fragment | String | `#section` |
1025-
| isAbsolute | Bool | `true` |
10261018

10271019
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:
10281020

0 commit comments

Comments
 (0)