W3cubDocs

/Nushell

str length for strings

Output the length of any strings in the pipeline.

Signature

> str length {flags} ...rest

Flags

  • --grapheme-clusters, -g: count length using grapheme clusters (all visible chars have length 1)
  • --utf-8-bytes, -b: count length using UTF-8 bytes (default; all non-ASCII chars have length 2+)

Parameters

  • ...rest: For a data structure input, replace strings at the given cell paths with their length

Input/output types:

input output
list<string> list<int>
record record
string int
table table

Examples

Return the lengths of a string

>'hello'|str length
5

Count length using grapheme clusters

>'๐Ÿ‡ฏ๐Ÿ‡ตใปใ’ ใตใŒ ใดใ‚ˆ'|str length-g
9

Return the lengths of multiple strings

> ['hi''there'] |str length
โ•ญโ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ•ฎ
โ”‚0โ”‚2โ”‚
โ”‚1โ”‚5โ”‚
โ•ฐโ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ•ฏ

Copyright ยฉ 2019โ€“2023 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/str_length.html