All Products
Search
Document Center

Resource Orchestration Service:Fn::Split

Last Updated:Mar 15, 2024

The built-in function Fn::Split splits a string into multiple values by using a delimiter.

Declaration

  • JSON

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

    • Syntax for the full function name:

      Fn::Split:
        - delimiter
        - original_string
    • Syntax for the short form:

      !Split [delimiter, original_string]

Parameters

  • delimiter: the delimiter, such as a comma (,), a semicolon (;), a line feed (\n), or an indent (\t).

  • original_string: the string that you want to split into multiple values.

Return value

The split string values.

Examples

  • In the following example, the Fn::Split function is used to split a string into an array of data elements:

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

    In this example, ["foo","bar","achoo"] is returned.

  • In the following example, the Fn::Split function is used to split the value of 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"}
              ]
            }
          }
        }
      }
    }

Supported functions