すべてのプロダクト
Search
ドキュメントセンター

Resource Orchestration Service:Fn::Split

最終更新日:Jan 16, 2025

組み込み関数 Fn::Split は、デリミタを使用して文字列を複数の値に分割します。

宣言

  • JSON

    {
      "Fn::Split": [
        "delimiter",
        "original_string"
      ]
    }
  • YAML

    • 完全な関数名の構文:

      Fn::Split:
        - delimiter
        - original_string
    • 短縮形の構文:

      !Split [delimiter, original_string]

パラメータ

  • delimiter: デリミタ。カンマ (,)、セミコロン (;)、改行 (\n)、またはインデント (\t) など。

  • original_string: 複数の値に分割する文字列。

戻り値

分割された文字列値。

  • 次の例では、Fn::Split 関数を使用して、文字列をデータ要素の配列に分割します。

    !Split
      - ;
      - foo; bar; achoo
    {
      "Fn::Split": [
        ";",
        "foo; bar; achoo"
      ]
    }

    この例では、["foo","bar","achoo"] が返されます。

  • 次の例では、Fn::Split 関数を使用して、InstanceIds の値を分割します。

    Parameters:
      InstanceIds:
        Type: String
        Default: instane1_id,instance2_id,instance2_id
    Resources:
      a:
        Type: ALIYUN::SLB::BackendServerAttachment
        Properties:
          BackendServerList:
            !Split
              - ','
              - !Ref InstanceIds
    {
      "Parameters": {
        "InstanceIds": {
          "Type": "String",
          "Default": "instane1_id,instance2_id,instance2_id"
        }
      },
      "Resources": {
        "a": {
          "Type": "ALIYUN::SLB::BackendServerAttachment",
          "Properties": {
            "BackendServerList": {
              "Fn::Split": [
                ",",
                {"Ref": "InstanceIds"}
              ]
            }
          }
        }
      }
    }

サポートされている関数