---
title: Work with strings
description: A string type represents a sequence of characters. Learn how to work with string data types in Flux.
url: https://docs.influxdata.com/flux/v0/data-types/basic/string/
estimated_tokens: 1664
product: Flux
version: v0
publisher: InfluxData
canonical: https://docs.influxdata.com/flux/v0/data-types/basic/string/
date: '2023-11-06T17:08:22-07:00'
lastmod: '2023-11-06T17:08:22-07:00'
---

A **string** type represents a sequence of characters.
Strings are immutable and cannot be modified once created.

**Type name**: `string`

* [String syntax](#string-syntax)
* [Convert data types to strings](#convert-data-types-to-strings)
* [Operate on strings](#operate-on-strings)
* [Interpolate strings](#interpolate-strings)
* [Concatenate strings](#concatenate-strings)

## String syntax

A **string** literal is represented by a sequence of characters enclosed in double quotes (`"`).
Any character may appear inside a string literal except an unescaped double quote.
String literals support several [escape sequences](/flux/v0/spec/lexical-elements/#string-literals)and [hex encoding using `\x` as a prefix](/flux/v0/spec/lexical-elements/#string-literals).

```js
"abc"
"string with double \" quote"
"string with backslash \\"
"日本語"
"\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
```

## Convert data types to strings

Use the [`string()` function](/flux/v0/stdlib/universe/string/) to convert
other [basic types](/flux/v0/data-types/basic/) to strings:

* boolean
* bytes
* duration
* float
* int
* uint
* time

```
string(v: 42)
// Returns "42"

```

### Convert regular expressions to strings

To convert a [regular expression](/flux/v0/data-types/basic/regexp/) to a string:

1. Import the [`regexp` package](/flux/v0/stdlib/regexp/).
2. Use [`regexp.getString()`](/flux/v0/stdlib/regexp/getstring/) and provide
   the regular expression to convert to a string.

```
import "regexp"

regexp.getString(r: /[a-zA-Z]/)
// Returns [a-zA-Z] (string)

```

### Convert data types to hexadecimal strings

To convert [basic types](/flux/v0/data-types/basic/) to hexadecimal strings:

1. Import the [`contrib/bonitoo-io/hex` package](/flux/v0/stdlib/contrib/bonitoo-io/hex/).
2. Use [`hex.string()`](/flux/v0/stdlib/contrib/bonitoo-io/hex/string/) to convert
   other a value to a hexadecimal string.

```
import "contrib/bonitoo-io/hex"

hex.string(v: 123456)
// Returns 1e240

```

### Convert columns to strings

Flux lets you iterate over rows in a [stream of tables](/flux/v0/get-started/data-model/#stream-of-tables)and convert columns to strings.

**To convert the `_value` column to strings**,
use the [`toString()` function](/flux/v0/stdlib/universe/tostring/).

> [!Note]
> `toString()` only operates on the `_value` column.

```js
data
    |> toString()
```

##### Given the following input data:

|       \_time       |\_value *(int)*|
|--------------------|---------------|
|2021-01-01T00:00:00Z|       1       |
|2021-01-01T02:00:00Z|       2       |
|2021-01-01T03:00:00Z|       3       |
|2021-01-01T04:00:00Z|       4       |

##### The example above returns:

|       \_time       |\_value *(string)*|
|--------------------|------------------|
|2021-01-01T00:00:00Z|        1         |
|2021-01-01T02:00:00Z|        2         |
|2021-01-01T03:00:00Z|        3         |
|2021-01-01T04:00:00Z|        4         |

**To convert any column to strings**:

1. Use [`map()`](/flux/v0/stdlib/universe/map/) to iterate over and rewrite rows.
2. Use [`string()`](/flux/v0/stdlib/universe/string/) to convert columns values to strings.

```js
data
    |> map(fn: (r) => ({ r with level: string(v: r.level) }))
```

##### Given the following input data:

|       \_time       |level *(int)*|
|--------------------|-------------|
|2021-01-01T00:00:00Z|      1      |
|2021-01-01T02:00:00Z|      2      |
|2021-01-01T03:00:00Z|      3      |
|2021-01-01T04:00:00Z|      4      |

##### The example above returns:

|       \_time       |level *(string)*|
|--------------------|----------------|
|2021-01-01T00:00:00Z|       1        |
|2021-01-01T02:00:00Z|       2        |
|2021-01-01T03:00:00Z|       3        |
|2021-01-01T04:00:00Z|       4        |

## Operate on strings

Use functions in the [Flux strings package](/flux/v0/stdlib/strings/) to perform
operations including:

* [Compare two strings](/flux/v0/stdlib/strings/compare/)
* [Replace substrings in a string](/flux/v0/stdlib/strings/replace/)
* [Return the length of a string](/flux/v0/stdlib/strings/strlen/)
* [Split a string into an array](/flux/v0/stdlib/strings/split/)
* [Join an array into a string](/flux/v0/stdlib/strings/joinstr/)
* [and more](/flux/v0/stdlib/strings/)

## Interpolate strings

To interpolate strings in another Flux string, enclose embedded [expressions](/flux/v0/spec/expressions/)in a dollar sign and curly braces `${}`.
Flux replaces the placeholder with the result of the embedded expression and
returns a string literal.

```
name = "John"
"My name is ${name}."
// My name is John.

d = 1m
"the answer is ${d}"
// the answer is 1m

t0 = 2016-06-13T17:43:50Z
"the answer is ${t0}"
// the answer is 2016-06-13T17:43:50.000000000Z

p = {name: "John", age: 42}
"My name is ${p.name} and I'm ${p.age} years old."
// My name is John and I'm 42 years old.

```

*String interpolation expressions must satisfy the[Stringable constraint](/flux/v0/spec/types/#stringable-constraint).*

## Concatenate strings

To concatenate Flux strings, use the `+` operator between string values or[expressions](/flux/v0/spec/expressions/) that resolve to strings.
Flux resolves expressions and returns a single concatenated string.

> [!Note]
> Concatenated expressions must resolve to strings.

```
name = "John"
"My name is " + name + "."
// My name is John.

d = 1m
"the answer is " + string(v: d)
// the answer is 1m

t0 = 2016-06-13T17:43:50Z
"the answer is " + string(v: t0)
// the answer is 2016-06-13T17:43:50.000000000Z

p = {name: "John", age: 42}
"My name is " + p.name + " and I'm " + string(v: p.age) + " years old."
// My name is John and I'm 42 years old.

```

#### Related

* [string() function](/flux/v0/stdlib/universe/string/)
* [toString() function](/flux/v0/stdlib/universe/tostring/)
* [strings package](/flux/v0/stdlib/strings/)

[basic types](/flux/v0/tags/basic-types/)[data types](/flux/v0/tags/data-types/)
| _time | _value  (int) |
| --- | --- |
| _time | _value  (int) |
| 2021-01-01T00:00:00Z | 1 |
| 2021-01-01T02:00:00Z | 2 |
| 2021-01-01T03:00:00Z | 3 |
| 2021-01-01T04:00:00Z | 4 |

| _time | _value  (string) |
| --- | --- |
| _time | _value  (string) |
| 2021-01-01T00:00:00Z | 1 |
| 2021-01-01T02:00:00Z | 2 |
| 2021-01-01T03:00:00Z | 3 |
| 2021-01-01T04:00:00Z | 4 |

| _time | level  (int) |
| --- | --- |
| _time | level  (int) |
| 2021-01-01T00:00:00Z | 1 |
| 2021-01-01T02:00:00Z | 2 |
| 2021-01-01T03:00:00Z | 3 |
| 2021-01-01T04:00:00Z | 4 |

| _time | level  (string) |
| --- | --- |
| _time | level  (string) |
| 2021-01-01T00:00:00Z | 1 |
| 2021-01-01T02:00:00Z | 2 |
| 2021-01-01T03:00:00Z | 3 |
| 2021-01-01T04:00:00Z | 4 |
