Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Categories

    • Bits
    • Bytes
    • Chart
    • Conversions
    • Core
    • Database
    • Dataframe
    • Dataframe Or Lazyframe
    • Date
    • Debug
    • Default
    • Env
    • Experimental
    • Expression
    • Filesystem
    • Filters
    • Formats
    • Generators
    • Hash
    • History
    • Lazyframe
    • Math
    • Misc
    • Network
    • Path
    • Platform
    • Plugin
    • Prompt
    • Random
    • Removed
    • Shells
    • Strings
    • System
    • Viewers

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:

inputoutput
stringint
list<string>list<int>
tabletable
recordrecord

Examples

Return the lengths of a string

> 'hello' | str length
5

Count length using grapheme clusters

> '🇯🇵ほげ ふが ぴよ' | str length  --grapheme-clusters
9

Return the lengths of multiple strings

> ['hi' 'there'] | str length
╭───┬───╮
│ 0 │ 2 │
│ 1 │ 5 │
╰───┴───╯