Back to Influxdb

strings.repeat() function

content/flux/v0/stdlib/strings/repeat.md

latest2.9 KB
Original Source
<!------------------------------------------------------------------------------ IMPORTANT: This page was generated from comments in the Flux source code. Any edits made directly to this page will be overwritten the next time the documentation is generated. To make updates to this documentation, update the function comments above the function definition in the Flux source code: https://github.com/influxdata/flux/blob/master/stdlib/strings/strings.flux#L629-L629 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

strings.repeat() returns a string consisting of i copies of a specified string.

Function type signature
js
(i: int, v: string) => string

{{% caption %}} For more information, see Function type signatures. {{% /caption %}}

Parameters

v

({{< req >}}) String value to repeat.

i

({{< req >}}) Number of times to repeat v.

Examples

Repeat a string based on existing columns

js
import "strings"

data
    |> map(fn: (r) => ({r with _value: strings.repeat(v: "ha", i: r._value)}))

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

_time_value*tag
2021-01-01T00:00:00Z1t1
2021-01-01T00:00:10Z5t1
2021-01-01T00:00:20Z3t1
2021-01-01T00:00:30Z8t1
2021-01-01T00:00:40Z7t1
2021-01-01T00:00:50Z2t1
_time_value*tag
2021-01-01T00:00:00Z9t2
2021-01-01T00:00:10Z2t2
2021-01-01T00:00:20Z1t2
2021-01-01T00:00:30Z9t2
2021-01-01T00:00:40Z6t2
2021-01-01T00:00:50Z0t2

Output data

_time_value*tag
2021-01-01T00:00:00Zhat1
2021-01-01T00:00:10Zhahahahahat1
2021-01-01T00:00:20Zhahahat1
2021-01-01T00:00:30Zhahahahahahahahat1
2021-01-01T00:00:40Zhahahahahahahat1
2021-01-01T00:00:50Zhahat1
_time_value*tag
2021-01-01T00:00:00Zhahahahahahahahahat2
2021-01-01T00:00:10Zhahat2
2021-01-01T00:00:20Zhat2
2021-01-01T00:00:30Zhahahahahahahahahat2
2021-01-01T00:00:40Zhahahahahahat2
2021-01-01T00:00:50Zt2

{{% /expand %}} {{< /expand-wrapper >}}