共用方式為


ARM 範本的字串函式

資源管理員會提供以下的函式,可在 Azure Resource Manager 範本 (ARM 範本) 中用來處理字串:

提示

建議使用 Bicep,因為它提供與 ARM 範本相同的功能,而且語法更容易使用。 若要深入了解,請參閱字串函式。

base64

base64(inputString)

傳回輸入字串的 base64 表示法。

在 Bicep 中,使用 函 base64 式。

參數

參數 必要 類型 描述
inputString Yes 字串 要以 base64 表示法傳回的值。

傳回值

字串,包含 base64 表示法。

範例

下列範例示範如何使用 base64 函數︰

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storageResourceGroup": {
      "type": "string"
    },
    "storageAccountName": {
      "type": "string"
    }
  },
  "resources": [],
  "outputs": {
    "ExistingStorage": {
      "type": "object",
      "value": "[reference(resourceId(parameters('storageResourceGroup'), 'Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2021-04-01')]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
base64Output String b25lLCB0d28sIHRocmVl
toStringOutput String 一二三
toJsonOutput Object {“one”: “a”, “two”: “b”}

base64ToJson

base64ToJson(base64Value)

將 base64 表示法轉換為 JSON 物件。

在 Bicep 中,使用 函 base64ToJson 式。

參數

參數 必要 類型 描述
base64Value Yes 字串 要轉換為 JSON 物件的 base64 表示法。

傳回值

JSON 物件。

範例

下列範例使用 base64ToJson 函式來轉換 base64 值︰

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storageResourceGroup": {
      "type": "string"
    },
    "storageAccountName": {
      "type": "string"
    }
  },
  "resources": [],
  "outputs": {
    "ExistingStorage": {
      "type": "object",
      "value": "[reference(resourceId(parameters('storageResourceGroup'), 'Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2021-04-01')]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
base64Output String b25lLCB0d28sIHRocmVl
toStringOutput String 一二三
toJsonOutput Object {“one”: “a”, “two”: “b”}

base64ToString

base64ToString(base64Value)

將 base64 表示法轉換為字串。

在 Bicep 中,使用 函 base64ToString 式。

參數

參數 必要 類型 描述
base64Value Yes 字串 要轉換為字串的 base64 表示法。

傳回值

轉換後之 base64 值的字串。

範例

下列範例使用 base64ToString 函式來轉換 base64 值︰

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storageResourceGroup": {
      "type": "string"
    },
    "storageAccountName": {
      "type": "string"
    }
  },
  "resources": [],
  "outputs": {
    "ExistingStorage": {
      "type": "object",
      "value": "[reference(resourceId(parameters('storageResourceGroup'), 'Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2021-04-01')]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
base64Output String b25lLCB0d28sIHRocmVl
toStringOutput String 一二三
toJsonOutput Object {“one”: “a”, “two”: “b”}

concat

concat(arg1, arg2, arg3, ...)

結合多個字串值並傳回串連字串,或結合多個陣列並傳回串連陣列。

在 Bicep 中,使用字串插補 (部分機器翻譯),而不是使用 concat() 函式以改善可讀性。 不過,在某些情況下,例如 多行字串中的字串取代,您可能需要使用 concat() 函式或函 replace() 式來回溯。

參數

參數 必要 類型 描述
arg1 Yes 字串或陣列 串連的第一個字串或陣列。
更多引數 No 字串或陣列 串連的其他字串或陣列 (循序順序)。

此函式可以接受任意數目的自變數,並可接受參數的字串或陣列。 但您無法為參數提供陣列和字串。 字串只能與其他字串串連。

傳回值

串連值的字串或陣列。

範例

下列範例示範如何結合兩個字串值並傳回串連字串:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "prefix": {
      "type": "string",
      "defaultValue": "prefix"
    }
  },
  "resources": [],
  "outputs": {
    "concatOutput": {
      "type": "string",
      "value": "[concat(parameters('prefix'), '-', uniqueString(resourceGroup().id))]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
concatOutput String prefix-5yj4yjf5mbg72

下列範例示範如何結合兩個陣列:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "firstArray": {
      "type": "array",
      "defaultValue": [
        "1-1",
        "1-2",
        "1-3"
      ]
    },
    "secondArray": {
      "type": "array",
      "defaultValue": [
        "2-1",
        "2-2",
        "2-3"
      ]
    }
  },
  "resources": [
  ],
  "outputs": {
    "return": {
      "type": "array",
      "value": "[concat(parameters('firstArray'), parameters('secondArray'))]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
return 陣列 ["1-1", "1-2", "1-3", "2-1", "2-2", "2-3"]

contains

contains(container, itemToFind)

檢查陣列是否包含值、物件包含索引鍵,或字串包含子字串。 字串比較會區分大小寫。 不過,測試時,如果物件包含索引鍵,比較便不區分大小寫。

在 Bicep 中,使用 函 contains 式。

參數

參數 必要 類型 描述
容器 Yes 陣列、物件或字串 其中包含要尋找之值的值。
itemToFind Yes 字串或整數 要尋找的值。

傳回值

True 如果找到專案,則為 ;否則為 False

範例

下列範例示範如何搭配不同類型的使用 contains

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "stringToTest": {
      "type": "string",
      "defaultValue": "OneTwoThree"
    },
    "objectToTest": {
      "type": "object",
      "defaultValue": {
        "one": "a",
        "two": "b",
        "three": "c"
      }
    },
    "arrayToTest": {
      "type": "array",
      "defaultValue": [ "one", "two", "three" ]
    }
  },
  "resources": [
  ],
  "outputs": {
    "stringTrue": {
      "type": "bool",
      "value": "[contains(parameters('stringToTest'), 'e')]"
    },
    "stringFalse": {
      "type": "bool",
      "value": "[contains(parameters('stringToTest'), 'z')]"
    },
    "objectTrue": {
      "type": "bool",
      "value": "[contains(parameters('objectToTest'), 'one')]"
    },
    "objectFalse": {
      "type": "bool",
      "value": "[contains(parameters('objectToTest'), 'a')]"
    },
    "arrayTrue": {
      "type": "bool",
      "value": "[contains(parameters('arrayToTest'), 'three')]"
    },
    "arrayFalse": {
      "type": "bool",
      "value": "[contains(parameters('arrayToTest'), 'four')]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
stringTrue Bool True
stringFalse Bool False
objectTrue Bool True
objectFalse Bool False
arrayTrue Bool True
arrayFalse Bool False

dataUri

dataUri(stringToConvert)

將值轉換為資料 URI。

在 Bicep 中,使用 函 dataUri 式。

參數

參數 必要 類型 描述
stringToConvert Yes 字串 要轉換為資料 URI 的值。

傳回值

格式化為資料 URI 的字串。

範例

下列範例會將值轉換成資料 URI,並將資料 URI 轉換成字串:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "stringToTest": {
      "type": "string",
      "defaultValue": "Hello"
    },
    "dataFormattedString": {
      "type": "string",
      "defaultValue": "data:;base64,SGVsbG8sIFdvcmxkIQ=="
    }
  },
  "resources": [],
  "outputs": {
    "dataUriOutput": {
      "value": "[dataUri(parameters('stringToTest'))]",
      "type": "string"
    },
    "toStringOutput": {
      "type": "string",
      "value": "[dataUriToString(parameters('dataFormattedString'))]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
dataUriOutput String data:text/plain;charset=utf8;base64,SGVsbG8=
toStringOutput String 世界您好!

dataUriToString

dataUriToString(dataUriToConvert)

將資料 URI 格式化值轉換為字串。

在 Bicep 中,使用 函 dataUriToString 式。

參數

參數 必要 類型 描述
dataUriToConvert Yes 字串 要轉換的資料 URI 值。

傳回值

字串,包含已轉換的值。

範例

下列範例範本會將值轉換成資料 URI,並將資料 URI 轉換成字串:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "stringToTest": {
      "type": "string",
      "defaultValue": "Hello"
    },
    "dataFormattedString": {
      "type": "string",
      "defaultValue": "data:;base64,SGVsbG8sIFdvcmxkIQ=="
    }
  },
  "resources": [],
  "outputs": {
    "dataUriOutput": {
      "value": "[dataUri(parameters('stringToTest'))]",
      "type": "string"
    },
    "toStringOutput": {
      "type": "string",
      "value": "[dataUriToString(parameters('dataFormattedString'))]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
dataUriOutput String data:text/plain;charset=utf8;base64,SGVsbG8=
toStringOutput String 世界您好!

empty

empty(itemToTest)

判斷陣列、物件或字串是否空白。

在 Bicep 中,使用 函 empty 式。

參數

參數 必要 類型 描述
itemToTest Yes 陣列、物件或字串 檢查其是否為空白的值。

傳回值

如果值是空的,則傳 True 回 ,否則傳 False回 。

範例

下列範例會檢查陣列、物件和字串是否為空的:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "testArray": {
      "type": "array",
      "defaultValue": []
    },
    "testObject": {
      "type": "object",
      "defaultValue": {}
    },
    "testString": {
      "type": "string",
      "defaultValue": ""
    }
  },
  "resources": [
  ],
  "outputs": {
    "arrayEmpty": {
      "type": "bool",
      "value": "[empty(parameters('testArray'))]"
    },
    "objectEmpty": {
      "type": "bool",
      "value": "[empty(parameters('testObject'))]"
    },
    "stringEmpty": {
      "type": "bool",
      "value": "[empty(parameters('testString'))]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
arrayEmpty Bool True
objectEmpty Bool True
stringEmpty Bool True

endsWith

endsWith(stringToSearch, stringToFind)

判斷字串是否以 值結尾。 此比較不區分大小寫。

在 Bicep 中,使用 函 endsWith 式。

參數

參數 必要 類型 描述
stringToSearch Yes 字串 其中包含要尋找之項目的值。
stringToFind Yes 字串 要尋找的值。

傳回值

True 如果字串的最後一個字元或字元符合值,則為 ;否則為 False

範例

下列範例說明如何使用 startsWithendsWith 函式:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [],
  "outputs": {
    "startsTrue": {
      "type": "bool",
      "value": "[startsWith('abcdef', 'ab')]"
    },
    "startsCapTrue": {
      "type": "bool",
      "value": "[startsWith('abcdef', 'A')]"
    },
    "startsFalse": {
      "type": "bool",
      "value": "[startsWith('abcdef', 'e')]"
    },
    "endsTrue": {
      "type": "bool",
      "value": "[endsWith('abcdef', 'ef')]"
    },
    "endsCapTrue": {
      "type": "bool",
      "value": "[endsWith('abcdef', 'F')]"
    },
    "endsFalse": {
      "type": "bool",
      "value": "[endsWith('abcdef', 'e')]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
startsTrue Bool True
startsCapTrue Bool True
startsFalse Bool False
endsTrue Bool True
endsCapTrue Bool True
endsFalse Bool False

第一

first(arg1)

傳回字串的第一個字元或陣列的第一個元素。 如果指定空字串,函式會產生空字串。 如果是空陣列,函式會傳回 null

在 Bicep 中,使用 函 first 式。

參數

參數 必要 類型 描述
arg1 Yes 陣列或字串 要擷取其第一個元素或字元的值。

傳回值

陣列中第一個字元的字串或陣列中第一個項目的類型(string、int、array 或 object)。

範例

下列範例示範如何使用 first 函式搭配數位和字串:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "arrayToTest": {
      "type": "array",
      "defaultValue": [ "one", "two", "three" ]
    }
  },
  "resources": [
  ],
  "outputs": {
    "arrayOutput": {
      "type": "string",
      "value": "[first(parameters('arrayToTest'))]"
    },
    "stringOutput": {
      "type": "string",
      "value": "[first('One Two Three')]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
arrayOutput String 一個
stringOutput String O

format

format(formatString, arg1, arg2, ...)

從輸入值建立格式化字串。

在 Bicep 中,使用 函 format 式。

參數

參數 必要 類型 描述
formatString Yes 字串 複合格式字串。
arg1 Yes 字串、整數或布林值 要納入格式化字串的值。
更多引數 No 字串、整數或布林值 要納入格式化字串的其他值。

備註

使用此函式來格式化範本中的字串。 此函式使用的格式化選項與 .NET 中的 System.String.Format 方法相同。

範例

下列範例示範如何使用 format 函數︰

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "greeting": {
      "type": "string",
      "defaultValue": "Hello"
    },
    "name": {
      "type": "string",
      "defaultValue": "User"
    },
    "numberToFormat": {
      "type": "int",
      "defaultValue": 8175133
    }
  },
  "resources": [
  ],
  "outputs": {
    "formatTest": {
      "type": "string",
      "value": "[format('{0}, {1}. Formatted number: {2:N0}', parameters('greeting'), parameters('name'), parameters('numberToFormat'))]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
formatTest String 您好,使用者。 格式化數字:8,175,133

guid

guid(baseString, ...)

建立一個值,格式為根據提供作為參數之值的全域唯一識別碼。

在 Bicep 中,使用 函 guid 式。

參數

參數 必要 類型 描述
baseString Yes 字串 雜湊函式中用來建立 GUID 的值。
更多參數 (如有需要) No 字串 您可以視需要新增多個字串,來建立指定唯一性層級的值。

備註

當您需要建立格式為全域唯一識別碼的值時,此函式很有幫助。 您提供限制結果唯一性範圍的參數值。 您可以指定名稱是否為訂用帳戶、資源群組或部署的唯一名稱。

傳回的值不是隨機字串,而是參數的雜湊函式結果。 傳回的值為 36 個字元長。 這不是全域唯一的值。 若要根據參數的哈希值建立新的 GUID,請使用 函 newGuid 式。

下列範例示範如何使用 guid 來建立常用層級的唯一值:

在訂用帳戶範圍內是唯一

"[guid(subscription().subscriptionId)]"

在資源群組範圍內是唯一

"[guid(resourceGroup().id)]"

在資源群組的部署範圍內是唯一

"[guid(resourceGroup().id, deployment().name)]"

guid 函式會根據 RFC 4122 §4.3 實作演算法。 原始來源可在 GuidUtility 中找到,其中有部分修改。 在函式實作中guid(),會設定為 namespaceId,而 11fb06fb-712d-4ddd-98c7-e71bbd588830 會設定為 version5 。 值是藉由將函式的每個參數 guid() 轉換成字串,並以分隔符串連它們 - 來產生。

傳回值

字串,包含 36 個字元,格式為全域唯一識別碼。

範例

下列範例會從 guid 傳回結果:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {},
  "variables": {},
  "resources": [],
  "outputs": {
    "guidPerSubscription": {
      "type": "string",
      "value": "[guid(subscription().subscriptionId)]"
    },
    "guidPerResourceGroup": {
      "type": "string",
      "value": "[guid(resourceGroup().id)]"
    },
    "guidPerDeployment": {
      "type": "string",
      "value": "[guid(resourceGroup().id, deployment().name)]"
    }
  }
}

indexOf

indexOf(stringToSearch, stringToFind)

傳回值在字串內的第一個位置。 此比較不區分大小寫。

在 Bicep 中,使用 函 indexOf 式。

參數

參數 必要 類型 描述
stringToSearch Yes 字串 其中包含要尋找之項目的值。
stringToFind Yes 字串 要尋找的值。

傳回值

整數,代表要尋找之項目的位置。 此值是以零為起始。 如果找不到該項目,則傳回 -1。

範例

下列範例說明如何使用 indexOflastIndexOf 函式:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [],
  "outputs": {
    "firstT": {
      "type": "int",
      "value": "[indexOf('test', 't')]"
    },
    "lastT": {
      "type": "int",
      "value": "[lastIndexOf('test', 't')]"
    },
    "firstString": {
      "type": "int",
      "value": "[indexOf('abcdef', 'CD')]"
    },
    "lastString": {
      "type": "int",
      "value": "[lastIndexOf('abcdef', 'AB')]"
    },
    "notFound": {
      "type": "int",
      "value": "[indexOf('abcdef', 'z')]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
firstT int 0
lastT int 3
firstString int 2
lastString int 0
notFound int -1

加入

join(inputArray, delimiter)

將字串陣列聯結成單一字串,並以分隔符號分隔。

在 Bicep 中,使用 函 join 式。

參數

參數 必要 類型 描述
inputArray Yes 字串陣列 要聯結的字串陣列。
分隔符號 Yes 用於分割字串的分隔符號。

傳回值

字串。

範例

下列範例會將輸入字串數位聯結至以不同分隔符分隔的字串:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "variables": {
    "arrayString": [
      "one",
      "two",
      "three"
    ]
  },
  "resources": [],
  "outputs": {
    "firstOutput": {
      "type": "string",
      "value": "[join(variables('arrayString'), ',')]"
    },
    "secondOutput": {
      "type": "string",
      "value": "[join(variables('arrayString'), ';')]"
    }
  }
}

前述範例的輸出為:

名稱 類型
firstOutput String "one,two,three"
secondOutput String "one;two;three"

json

json(arg1)

將有效的 JSON 字串轉換成 JSON 資料類型。 如需詳細資訊,請參閱 json 函式。

在 Bicep 中,使用 函 json 式。

最後一

last(arg1)

傳回字串的最後一個字元或陣列的最後一個元素。

在 Bicep 中,使用 函 last 式。

參數

參數 必要 類型 描述
arg1 Yes 陣列或字串 要擷取其最後一個元素或字元的值。

傳回值

陣列中最後一個字元的字串,或最後一個元素的類型 (字串、整數、陣列或物件)。

範例

下列範例示範如何使用 last 函式搭配數位和字串:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "arrayToTest": {
      "type": "array",
      "defaultValue": [ "one", "two", "three" ]
    }
  },
  "resources": [
  ],
  "outputs": {
    "arrayOutput": {
      "type": "string",
      "value": "[last(parameters('arrayToTest'))]"
    },
    "stringOutput": {
      "type": "string",
      "value": "[last('One Two Three')]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
arrayOutput String 3
stringOutput String e

lastIndexOf

lastIndexOf(stringToSearch, stringToFind)

傳回值在字串內的最後一個位置。 此比較不區分大小寫。

在 Bicep 中,使用 函 lastIndexOf 式。

參數

參數 必要 類型 描述
stringToSearch Yes 字串 其中包含要尋找之項目的值。
stringToFind Yes 字串 要尋找的值。

傳回值

整數,代表要尋找之項目的最後一個位置。 此值是以零為起始。 如果找不到該項目,則傳回 -1。

範例

下列範例說明如何使用 indexOflastIndexOf 函式:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [],
  "outputs": {
    "firstT": {
      "type": "int",
      "value": "[indexOf('test', 't')]"
    },
    "lastT": {
      "type": "int",
      "value": "[lastIndexOf('test', 't')]"
    },
    "firstString": {
      "type": "int",
      "value": "[indexOf('abcdef', 'CD')]"
    },
    "lastString": {
      "type": "int",
      "value": "[lastIndexOf('abcdef', 'AB')]"
    },
    "notFound": {
      "type": "int",
      "value": "[indexOf('abcdef', 'z')]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
firstT int 0
lastT int 3
firstString int 2
lastString int 0
notFound int -1

length

length(string)

傳回字串中的字元數、陣列中的元素數,或物件中根層級的屬性數。

在 Bicep 中,使用 函 length 式。

參數

參數 必要 類型 描述
arg1 Yes 陣列、字串或物件 用於取得元素數目的陣列、用於取得字元數目的字串,或用於取得根層級屬性數目的物件。

傳回值

整數。

範例

下列範例示範如何使用 length 函式搭配數位和字串:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "arrayToTest": {
      "type": "array",
      "defaultValue": [
        "one",
        "two",
        "three"
      ]
    },
    "stringToTest": {
      "type": "string",
      "defaultValue": "One Two Three"
    },
    "objectToTest": {
      "type": "object",
      "defaultValue": {
        "propA": "one",
        "propB": "two",
        "propC": "three",
        "propD": {
          "propD-1": "sub",
          "propD-2": "sub"
        }
      }
    }
  },
  "resources": [],
  "outputs": {
    "arrayLength": {
      "type": "int",
      "value": "[length(parameters('arrayToTest'))]"
    },
    "stringLength": {
      "type": "int",
      "value": "[length(parameters('stringToTest'))]"
    },
    "objectLength": {
      "type": "int",
      "value": "[length(parameters('objectToTest'))]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
arrayLength int 3
stringLength int 13
objectLength int 4

newGuid

newGuid()

以全域唯一識別碼格式傳回值。 此函式只能用於參數的預設值。

在 Bicep 中,使用 函 newGuid 式。

備註

您只能在運算式內使用此函式,以取得參數的預設值。 在 Bicep 檔案中的其他地方使用此函式會傳回錯誤。 在範本的其他部分不允許該函式,因為這會在每次呼叫時傳回不同的值。 使用相同的參數部署相同的範本,並不會確實產生相同的結果。

newGuid 函式與 guid 函式不同,因為它不會採用任何參數。 當您使用相同的參數呼叫 guid 時,每次都會傳回相同的識別碼。 當您需要針對特定環境確實地產生相同的 GUID 時,請使用 guid。 當您每次需要不同的識別碼 (例如將資源部署至測試環境) 時,請使用 newGuid。

newGuid 函式會使用 .NET Framework 中的 Guid 結構,產生全域唯一識別碼。

如果您使用 選項來重新部署先前成功的部署 ,其中先前的部署包含使用 newGuid的參數,則不會再次評估 參數。 相反地,復原部署會自動重複使用先前部署的參數值。

在測試環境中,您可能需要重複部署只短時間存留的資源。 您可以使用 newGuid 來 uniqueString 建立唯一名稱,而不是建構唯一的名稱。

請小心重新部署依賴 newGuid 函式的範本,以取得預設值。 當您重新部署且未提供參數的值時,會重新評估該函式。 如果您想更新現有的資源,而不是建立新的資源,請傳入來自先前部署的參數值。

傳回值

字串,包含 36 個字元,格式為全域唯一識別碼。

範例

下列範例顯示具有新識別碼的參數:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "guidValue": {
      "type": "string",
      "defaultValue": "[newGuid()]"
    }
  },
  "resources": [
  ],
  "outputs": {
    "guidOutput": {
      "type": "string",
      "value": "[parameters('guidValue')]"
    }
  }
}

前述範例的輸出會隨著個別部署而有所不同,但會類似於:

名稱 類型
guidOutput 字串 b76a51fc-bd72-4a77-b9a2-3c29e7d2e551

下列範例使用 newGuid 函式來建立儲存體帳戶的唯一名稱。 此樣本適用於短期內記憶體帳戶存在且不會再次部署的測試環境:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "guidValue": {
      "type": "string",
      "defaultValue": "[newGuid()]"
    }
  },
  "variables": {
    "storageName": "[concat('storage', uniqueString(parameters('guidValue')))]"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2025-06-01",
      "name": "[variables('storageName')]",
      "location": "West US",
      "sku": {
        "name": "Standard_LRS"
      },
      "kind": "StorageV2",
      "properties": {}
    }
  ],
  "outputs": {
    "nameOutput": {
      "type": "string",
      "value": "[variables('storageName')]"
    }
  }
}

前述範例的輸出會隨著個別部署而有所不同,但會類似於:

名稱 類型
nameOutput 字串 storagenziwvyru7uxie

padLeft

padLeft(valueToPad, totalLength, paddingCharacter)

藉由將字元新增至左邊,直到到達指定的總長度,以傳回靠右對齊的字串。

在 Bicep 中,使用 函 padLeft 式。

參數

參數 必要 類型 描述
valueToPad Yes 字串或整數 要靠右對齊的值。
totalLength Yes int 傳回字串中的字元總數。
paddingCharacter No 單一字元 要用於左側填補直到達到總長度的字元。 預設值是空格。

如果原始字串長度超過要填補的字元數,則不會新增任何字元。

傳回值

至少含有指定字元數的字串。

範例

下列範例示範如何新增 個字元,直到到達字元總數以填補使用者提供的參數值:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "testString": {
      "type": "string",
      "defaultValue": "123"
    }
  },
  "resources": [],
  "outputs": {
    "stringOutput": {
      "type": "string",
      "value": "[padLeft(parameters('testString'),10,'0')]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
stringOutput String 0000000123

取代

replace(originalString, oldString, newString)

傳回具備由另一個字串取代的一個字串之所有執行個體的新字串。

在 Bicep 中,使用 函 replace 式。

參數

參數 必要 類型 描述
originalString Yes 字串 具備由另一個字串取代的一個字串之所有執行個體的值。
oldString Yes 字串 要從原始字串中移除的字串。
newString Yes 字串 要新增來取代移除之字串的字串。

傳回值

具有已取代字元的字串。

範例

下列範例示範如何從使用者提供的字串中移除所有虛線,以及如何以另一個字串取代部分字串:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "testString": {
      "type": "string",
      "defaultValue": "123-123-1234"
    }
  },
  "resources": [],
  "outputs": {
    "firstOutput": {
      "type": "string",
      "value": "[replace(parameters('testString'),'-', '')]"
    },
    "secondOutput": {
      "type": "string",
      "value": "[replace(parameters('testString'),'1234', 'xxxx')]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
firstOutput String 1231231234
secondOutput String 123-123-xxxx

略過

skip(originalValue, numberToSkip)

傳回位於指定字元數目之後的所有字元所組成的字串,或傳回位於指定元素數目之後的所有元素所形成的陣列。

在 Bicep 中,使用 函 skip 式。

參數

參數 必要 類型 描述
originalValue Yes 陣列或字串 要用於略過的陣列或字串。
numberToSkip Yes int 要略過的元素或字元數。 如果此值為 0 或更小的值,則會傳回值內的所有元素或字元。 如果此值大於陣列或字串的長度,則會傳回空白的陣列或字串。

傳回值

陣列或字串。

範例

下列範例會略過陣列中指定的項目數目,以及字串中的指定字元數:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "testArray": {
      "type": "array",
      "defaultValue": [
        "one",
        "two",
        "three"
      ]
    },
    "elementsToSkip": {
      "type": "int",
      "defaultValue": 2
    },
    "testString": {
      "type": "string",
      "defaultValue": "one two three"
    },
    "charactersToSkip": {
      "type": "int",
      "defaultValue": 4
    }
  },
  "resources": [],
  "outputs": {
    "arrayOutput": {
      "type": "array",
      "value": "[skip(parameters('testArray'),parameters('elementsToSkip'))]"
    },
    "stringOutput": {
      "type": "string",
      "value": "[skip(parameters('testString'),parameters('charactersToSkip'))]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
arrayOutput 陣列 ["three"]
stringOutput String 兩個三

分割

split(inputString, delimiter)

傳回包含輸入字串之子字串的字串陣列,其中的子字串已使用指定的分隔符號分隔。

在 Bicep 中,使用 函 split 式。

參數

參數 必要 類型 描述
inputString Yes 字串 要分隔的字串。
分隔符號 Yes 字串或字串陣列 用於分割字串的分隔符號。

傳回值

字串的陣列。

範例

下列範例會以逗號分割輸入字串,並以逗號或分號分割下列字串:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "firstString": {
      "type": "string",
      "defaultValue": "one,two,three"
    },
    "secondString": {
      "type": "string",
      "defaultValue": "one;two,three"
    }
  },
  "variables": {
    "delimiters": [ ",", ";" ]
  },
  "resources": [],
  "outputs": {
    "firstOutput": {
      "type": "array",
      "value": "[split(parameters('firstString'),',')]"
    },
    "secondOutput": {
      "type": "array",
      "value": "[split(parameters('secondString'),variables('delimiters'))]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
firstOutput 陣列 [“one”, “two”, “three”]
secondOutput 陣列 [“one”, “two”, “three”]

startsWith

startsWith(stringToSearch, stringToFind)

判斷字串是否以 值開頭。 此比較不區分大小寫。

在 Bicep 中,使用 函 startsWith 式。

參數

參數 必要 類型 描述
stringToSearch Yes 字串 其中包含要尋找之項目的值。
stringToFind Yes 字串 要尋找的值。

傳回值

True 如果字串的第一個字元或字元符合值,則為 ;否則為 False

範例

下列範例說明如何使用 startsWithendsWith 函式:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [],
  "outputs": {
    "startsTrue": {
      "type": "bool",
      "value": "[startsWith('abcdef', 'ab')]"
    },
    "startsCapTrue": {
      "type": "bool",
      "value": "[startsWith('abcdef', 'A')]"
    },
    "startsFalse": {
      "type": "bool",
      "value": "[startsWith('abcdef', 'e')]"
    },
    "endsTrue": {
      "type": "bool",
      "value": "[endsWith('abcdef', 'ef')]"
    },
    "endsCapTrue": {
      "type": "bool",
      "value": "[endsWith('abcdef', 'F')]"
    },
    "endsFalse": {
      "type": "bool",
      "value": "[endsWith('abcdef', 'e')]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
startsTrue Bool True
startsCapTrue Bool True
startsFalse Bool False
endsTrue Bool True
endsCapTrue Bool True
endsFalse Bool False

字串

string(valueToConvert)

將指定的值轉換成字串。

在 Bicep 中,使用 函 string 式。

參數

參數 必要 類型 描述
valueToConvert Yes 任意 要轉換成字串的值。 任何類型的值均可轉換,包括物件和陣列。

傳回值

轉換值的字串。

範例

下列範例顯示如何將不同類型的值轉換為字串︰

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "testObject": {
      "type": "object",
      "defaultValue": {
        "valueA": 10,
        "valueB": "Example Text"
      }
    },
    "testArray": {
      "type": "array",
      "defaultValue": [
        "a",
        "b",
        "c"
      ]
    },
    "testInt": {
      "type": "int",
      "defaultValue": 5
    }
  },
  "resources": [],
  "outputs": {
    "objectOutput": {
      "type": "string",
      "value": "[string(parameters('testObject'))]"
    },
    "arrayOutput": {
      "type": "string",
      "value": "[string(parameters('testArray'))]"
    },
    "intOutput": {
      "type": "string",
      "value": "[string(parameters('testInt'))]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
objectOutput String {“valueA”:10,“valueB”:“範例文字”}
arrayOutput String ["a","b","c"]
intOutput String 5

substring

substring(stringToParse, startIndex, length)

傳回起始於指定字元位置的子字串,其中包含指定的字元數。

在 Bicep 中,使用 函 substring 式。

參數

參數 必要 類型 描述
stringToParse Yes 字串 要用來擷取子字串的原始字串。
startIndex No int 起始字元位置為零的子字串。
length No int 子字串的字元數。 必須參考字串內的位置。 必須是零或更大的值。 如果省略此值,則會傳回起始位置字串的其餘部分。

傳回值

子字串。 或著,如果長度為零,則為空字串。

備註

當子字串延伸超過字串的結尾,或當長度小於零時,此函式會失敗。 下列範例失敗並出現錯誤:「索引和長度參數必須參考字串內的位置。 索引參數: '0',length 參數: '11',字串參數的長度: '10'。

"parameters": {
  "inputString": {
    "type": "string",
    "value": "1234567890"
  }
}, "variables": {
  "prefix": "[substring(parameters('inputString'), 0, 11)]"
}

範例

下列範例會從 參數擷取子字串:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "testString": {
      "type": "string",
      "defaultValue": "one two three"
    }
  },
  "resources": [],
  "outputs": {
    "substringOutput": {
      "type": "string",
      "value": "[substring(parameters('testString'), 4, 3)]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
substringOutput String 2

take

take(originalValue, numberToTake)

傳回陣列或字串。 陣列從其開頭算起,含有指定數目的元素。 字串從其開頭算起,含有指定數目的字元。

在 Bicep 中,使用 函 take 式。

參數

參數 必要 類型 描述
originalValue Yes 陣列或字串 要從其中擷取元素的陣列或字串。
numberToTake Yes int 要擷取的元素或字元數。 如果此值為 0 或更小的值,則會傳回空白陣列或字串。 如果此值大於指定陣列或字串的長度,則會傳回陣列或字串中的所有元素。

傳回值

陣列或字串。

範例

下列範例會從陣列中取得指定的項目數目,以及字串中的字元:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "testArray": {
      "type": "array",
      "defaultValue": [
        "one",
        "two",
        "three"
      ]
    },
    "elementsToTake": {
      "type": "int",
      "defaultValue": 2
    },
    "testString": {
      "type": "string",
      "defaultValue": "one two three"
    },
    "charactersToTake": {
      "type": "int",
      "defaultValue": 2
    }
  },
  "resources": [],
  "outputs": {
    "arrayOutput": {
      "type": "array",
      "value": "[take(parameters('testArray'),parameters('elementsToTake'))]"
    },
    "stringOutput": {
      "type": "string",
      "value": "[take(parameters('testString'),parameters('charactersToTake'))]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
arrayOutput 陣列 [“one”, “two”]
stringOutput String on

toLower

toLower(stringToChange)

將指定的字串轉換為小寫。

在 Bicep 中,使用 函 toLower 式。

參數

參數 必要 類型 描述
stringToChange Yes 字串 要轉換成小寫字母的值。

傳回值

字串已轉換成小寫。

範例

下列範例會將參數值轉換成小寫和大寫:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "testString": {
      "type": "string",
      "defaultValue": "One Two Three"
    }
  },
  "resources": [],
  "outputs": {
    "toLowerOutput": {
      "type": "string",
      "value": "[toLower(parameters('testString'))]"
    },
    "toUpperOutput": {
      "type": "string",
      "value": "[toUpper(parameters('testString'))]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
toLowerOutput String 一二三
toUpperOutput String 一二三

toUpper

toUpper(stringToChange)

將指定的字串轉換為大寫。

在 Bicep 中,使用 函 toUpper 式。

參數

參數 必要 類型 描述
stringToChange Yes 字串 要轉換成大寫字母的值。

傳回值

字串已轉換成大寫。

範例

下列範例會將參數值轉換成小寫和大寫:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "testString": {
      "type": "string",
      "defaultValue": "One Two Three"
    }
  },
  "resources": [],
  "outputs": {
    "toLowerOutput": {
      "type": "string",
      "value": "[toLower(parameters('testString'))]"
    },
    "toUpperOutput": {
      "type": "string",
      "value": "[toUpper(parameters('testString'))]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
toLowerOutput String 一二三
toUpperOutput String 一二三

修剪

trim(stringToTrim)

從指定的字串中移除所有開頭和尾端空白字元。

在 Bicep 中,使用 函 trim 式。

參數

參數 必要 類型 描述
stringToTrim Yes 字串 要修剪的值。

傳回值

沒有開頭和尾端空白字元的字串。

範例

下列範例會從 參數修剪空格符:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "testString": {
      "type": "string",
      "defaultValue": "    one two three   "
    }
  },
  "resources": [],
  "outputs": {
    "return": {
      "type": "string",
      "value": "[trim(parameters('testString'))]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
return String 一二三

uniqueString

uniqueString(baseString, ...)

根據當作參數提供的值,建立具決定性的雜湊字串。

在 Bicep 中,使用 函 uniqueString 式。

參數

參數 必要 類型 描述
baseString Yes 字串 雜湊函式中用來建立唯一字串的值。
更多參數 (如有需要) No 字串 您可以視需要新增多個字串,來建立指定唯一性層級的值。

備註

當您需要建立資源的唯一名稱時,這個函式很有幫助。 您提供限制結果唯一性範圍的參數值。 您可以指定名稱是否為訂用帳戶、資源群組或部署的唯一名稱。

傳回的值不是隨機字串,而是哈希函式的結果。 傳回的值為 13 個字元長。 這不是全域唯一的值。 您可能想要將值與命名慣例中的前置詞結合,以建立有意義的名稱。 下列範例顯示傳回值的格式。 依提供的參數而改變的實際值。

tcvhiyu5h2o5o

下列範例示範如何使用 uniqueString 來建立常用層級的唯一值:

在訂用帳戶範圍內是唯一

"[uniqueString(subscription().subscriptionId)]"

在資源群組範圍內是唯一

"[uniqueString(resourceGroup().id)]"

在資源群組的部署範圍內是唯一

"[uniqueString(resourceGroup().id, deployment().name)]"

下列範例顯示如何根據您的資源群組建立儲存體帳戶的唯一名稱。 在資源群組內,如果名稱的建構方式相同,則名稱並不是唯一的:

"resources": [{
  "name": "[concat('storage', uniqueString(resourceGroup().id))]",
  "type": "Microsoft.Storage/storageAccounts",
  ...

如果您需要在每次部署範本時建立新的唯一名稱,而且不想要更新資源,您可以使用 函 utcNow 式搭配 uniqueString。 您可以在測試環境中使用此方法。 如需範例,請參閱 utcNow

傳回值

包含 13 個字元的字串。

範例

下列範例會從 uniquestring 傳回結果:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [],
  "outputs": {
    "uniqueRG": {
      "type": "string",
      "value": "[uniqueString(resourceGroup().id)]"
    },
    "uniqueDeploy": {
      "type": "string",
      "value": "[uniqueString(resourceGroup().id, deployment().name)]"
    }
  }
}

uri

uri(baseUri, relativeUri)

藉由結合 baseUri 和 relativeUri 字串建立絕對 URI。

在 Bicep 中,使用 函 uri 式。

參數

參數 必要 類型 描述
baseUri Yes 字串 基底 uri 的字串。 請仔細觀察處理尾端斜線 (/) 的相關行為,如下表所述。
relativeUri Yes 字串 要加入至基底 uri 字串的相對 uri 字串。
  • 如果 baseUri 以尾端斜線結尾,則結果後面只會 baseUri 接著 relativeUri。 如果 relativeUri 開頭為前置斜線,尾端斜線和前置斜線將會合併成一個。

  • 如果 baseUri 不會以尾端斜線結尾的兩件事之一結束。

    • 如果 baseUri 完全沒有斜線(除了 // 靠近前面),則結果 baseUri 後面接著 relativeUri

    • 如果 baseUri 有一些斜線,但不以斜線結尾,則會從 baseUri 移除最後一個斜線的所有專案,結果 baseUri 後面接著 relativeUri

以下列出一些範例:

uri('http://contoso.org/firstpath', 'myscript.sh') -> http://contoso.org/myscript.sh
uri('http://contoso.org/firstpath/', 'myscript.sh') -> http://contoso.org/firstpath/myscript.sh
uri('http://contoso.org/firstpath/', '/myscript.sh') -> http://contoso.org/firstpath/myscript.sh
uri('http://contoso.org/firstpath/azuredeploy.json', 'myscript.sh') -> http://contoso.org/firstpath/myscript.sh
uri('http://contoso.org/firstpath/azuredeploy.json/', 'myscript.sh') -> http://contoso.org/firstpath/azuredeploy.json/myscript.sh

如需完整詳細數據, baseUri 會解析 和 relativeUri 參數,如 RFC 3986 第 5 節中所指定。

傳回值

字串,代表基底和相對值的絕對 URI。

範例

下列範例示範如何根據父範本的值建構巢狀範本的連結:

"templateLink": "[uri(deployment().properties.templateLink.uri, 'nested/azuredeploy.json')]"

下列範例範本示範如何使用 uriuriComponenturiComponentToString

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "variables": {
    "uriFormat": "[uri('http://contoso.com/resources/', 'nested/azuredeploy.json')]",
    "uriEncoded": "[uriComponent(variables('uriFormat'))]"
  },
  "resources": [
  ],
  "outputs": {
    "uriOutput": {
      "type": "string",
      "value": "[variables('uriFormat')]"
    },
    "componentOutput": {
      "type": "string",
      "value": "[variables('uriEncoded')]"
    },
    "toStringOutput": {
      "type": "string",
      "value": "[uriComponentToString(variables('uriEncoded'))]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
uriOutput String http://contoso.com/resources/nested/azuredeploy.json
componentOutput String http%3A%2F%2Fcontoso.com%2Fresources%2Fnested%2Fazuredeploy.json
toStringOutput String http://contoso.com/resources/nested/azuredeploy.json

uriComponent

uricomponent(stringToEncode)

將 URI 編碼。

在 Bicep 中,使用 函 uriComponent 式。

參數

參數 必要 類型 描述
stringToEncode Yes 字串 要編碼的值。

傳回值

URI 編碼值的字串。

範例

下列範例範本示範如何使用 uriuriComponenturiComponentToString

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "variables": {
    "uriFormat": "[uri('http://contoso.com/resources/', 'nested/azuredeploy.json')]",
    "uriEncoded": "[uriComponent(variables('uriFormat'))]"
  },
  "resources": [
  ],
  "outputs": {
    "uriOutput": {
      "type": "string",
      "value": "[variables('uriFormat')]"
    },
    "componentOutput": {
      "type": "string",
      "value": "[variables('uriEncoded')]"
    },
    "toStringOutput": {
      "type": "string",
      "value": "[uriComponentToString(variables('uriEncoded'))]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
uriOutput String http://contoso.com/resources/nested/azuredeploy.json
componentOutput String http%3A%2F%2Fcontoso.com%2Fresources%2Fnested%2Fazuredeploy.json
toStringOutput String http://contoso.com/resources/nested/azuredeploy.json

uriComponentToString

uriComponentToString(uriEncodedString)

傳回 URI 編碼值的字串。

在 Bicep 中,使用 函 uriComponentToString 式。

參數

參數 必要 類型 描述
uriEncodedString Yes 字串 要轉換為字串的 URI 編碼值。

傳回值

URI 編碼值的解碼字串。

範例

下列範例示範如何使用 uriuriComponenturiComponentToString

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "variables": {
    "uriFormat": "[uri('http://contoso.com/resources/', 'nested/azuredeploy.json')]",
    "uriEncoded": "[uriComponent(variables('uriFormat'))]"
  },
  "resources": [
  ],
  "outputs": {
    "uriOutput": {
      "type": "string",
      "value": "[variables('uriFormat')]"
    },
    "componentOutput": {
      "type": "string",
      "value": "[variables('uriEncoded')]"
    },
    "toStringOutput": {
      "type": "string",
      "value": "[uriComponentToString(variables('uriEncoded'))]"
    }
  }
}

上述範例的預設值輸出如下:

名稱 類型
uriOutput String http://contoso.com/resources/nested/azuredeploy.json
componentOutput String http%3A%2F%2Fcontoso.com%2Fresources%2Fnested%2Fazuredeploy.json
toStringOutput String http://contoso.com/resources/nested/azuredeploy.json

下一步