str trim

For strings.

Trim whitespace or specific character.

Command Type

built-in

Signature

> str trim {flags} ...rest

Flags

  • --char, -c {string}: Character to trim (default: whitespace).
  • --left, -l: Trims characters only from the beginning of the string.
  • --right, -r: Trims characters only from the end of the string.

Parameters

  • ...rest: For a data structure input, trim strings at the given cell paths.

Input/output types:

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

Examples

Trim whitespace.

> 'Nu shell ' | str trim
Nu shell

Trim a specific character (not the whitespace).

> '=== Nu shell ===' | str trim --char '='
 Nu shell

Trim whitespace from the beginning of string.

> ' Nu shell ' | str trim --left
Nu shell

Trim whitespace from the end of string.

> ' Nu shell ' | str trim --right
 Nu shell

Trim a specific character only from the end of the string.

> '=== Nu shell ===' | str trim --right --char '='
=== Nu shell

Ported from nushell/nushell.github.io. Copyright (c) 2021 Nushell Project. MIT License.