The Workflows syntax supports a string data type with UTF‑8
encoding ([maximum length](https://docs.cloud.google.com/workflows/quotas#resource_limits)).

For information on conversion and built-in string functions, see
[Data types, functions, operators](https://docs.cloud.google.com/workflows/docs/reference/syntax/datatypes).

For other text processing functions, see the Workflows standard
library [`text` module reference](https://docs.cloud.google.com/workflows/docs/reference/stdlib/overview#module:-text).

## Assign a string variable

The value of a static string can be assigned to a variable. For example:

### YAML

```yaml
  - step:
      assign:
        - string: "hello"
  
```

### JSON

```json
  [
    {
      "step": {
        "assign": [
          {
            "string": "hello"
          }
        ]
      }
    }
  ]
    
```

## Concatenate using expressions

You can dynamically concatenate strings using expressions and the `+` operator.
For example:

<br />

### YAML

```yaml
    - step:
        assign:
          - outputVar: ${"Hello, " + firstName}
    
```

### JSON

```json
    [
      {
        "step": {
          "assign": [
            {
              "outputVar": "${\"Hello \" + firstName}"
            }
          ]
        }
      }
    ]
```

<br />

> [!IMPORTANT]
> **Important:** In YAML, expressions containing colons can cause unexpected behaviour when the colon is interpreted as defining a map. You can resolve this issue by wrapping the YAML expression in single quotes:
>
> Recommended: `'${"thisVar: " + myVar}'`
>
> Not recommended: `${"thisVar: " + myVar}`
> For details, see [Expressions containing colons](https://docs.cloud.google.com/workflows/docs/troubleshooting#expressions-colons).

## Concatenate over multiple lines

Since each assignment is processed sequentially, you can concatenate a string
over multiple lines by repeating the variable and splitting the assignment. For
example:

### YAML

```yaml
main:
  steps:
    - assign_vars:
        assign:
          - concatLines: "say"
          - concatLines: ${concatLines+" "+"hello"}
          - concatLines: ${concatLines+" "+"to the world"}
    - returnOutput:
        return: ${concatLines}
```

### JSON

```json
{
  "main": {
    "steps": [
      {
        "assign_vars": {
          "assign": [
            {
              "concatLines": "say"
            },
            {
              "concatLines": "${concatLines+\" \"+\"hello\"}"
            },
            {
              "concatLines": "${concatLines+\" \"+\"to the world\"}"
            }
          ]
        }
      },
      {
        "returnOutput": {
          "return": "${concatLines}"
        }
      }
    ]
  }
}
```