Back to Influxdb

strings.strlen() function

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

latest4.3 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#L811-L811 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

strings.strlen() returns the length of a string. String length is determined by the number of UTF code points a string contains.

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

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

Parameters

v

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

Examples

Filter based on string value length

js
import "strings"

data
    |> filter(fn: (r) => strings.strlen(v: r._value) <= 6)

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

Input data

_time_value*tag
2021-01-01T00:00:00Zpl_gqczt1
2021-01-01T00:00:10Zpl_gvnt1
2021-01-01T00:00:20Zpl_phwt1
2021-01-01T00:00:30Zpl_guvzyt1
2021-01-01T00:00:40Zpl_vccet1
2021-01-01T00:00:50Zpl_fgyt1
_time_value*tag
2021-01-01T00:00:00Zpl_beidat2
2021-01-01T00:00:10Zpl_euoxpt2
2021-01-01T00:00:20Zpl_gtzt2
2021-01-01T00:00:30Zpl_oxutt2
2021-01-01T00:00:40Zpl_wft2
2021-01-01T00:00:50Zpl_dtnbvt2

Output data

_time_value*tag
2021-01-01T00:00:10Zpl_gvnt1
2021-01-01T00:00:20Zpl_phwt1
2021-01-01T00:00:50Zpl_fgyt1
_time_value*tag
2021-01-01T00:00:20Zpl_gtzt2
2021-01-01T00:00:40Zpl_wft2

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

Store the length of string values

js
import "strings"

data
    |> map(fn: (r) => ({r with length: strings.strlen(v: r._value)}))

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

Input data

_time_value*tag
2021-01-01T00:00:00Zpl_gqczt1
2021-01-01T00:00:10Zpl_gvnt1
2021-01-01T00:00:20Zpl_phwt1
2021-01-01T00:00:30Zpl_guvzyt1
2021-01-01T00:00:40Zpl_vccet1
2021-01-01T00:00:50Zpl_fgyt1
_time_value*tag
2021-01-01T00:00:00Zpl_beidat2
2021-01-01T00:00:10Zpl_euoxpt2
2021-01-01T00:00:20Zpl_gtzt2
2021-01-01T00:00:30Zpl_oxutt2
2021-01-01T00:00:40Zpl_wft2
2021-01-01T00:00:50Zpl_dtnbvt2

Output data

_time_valuelength*tag
2021-01-01T00:00:00Zpl_gqcz7t1
2021-01-01T00:00:10Zpl_gvn6t1
2021-01-01T00:00:20Zpl_phw6t1
2021-01-01T00:00:30Zpl_guvzy8t1
2021-01-01T00:00:40Zpl_vcce7t1
2021-01-01T00:00:50Zpl_fgy6t1
_time_valuelength*tag
2021-01-01T00:00:00Zpl_beida8t2
2021-01-01T00:00:10Zpl_euoxp8t2
2021-01-01T00:00:20Zpl_gtz6t2
2021-01-01T00:00:30Zpl_oxut7t2
2021-01-01T00:00:40Zpl_wf5t2
2021-01-01T00:00:50Zpl_dtnbv8t2

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