Collapse

str_collapse

Collapse all runs of whitespace in a string down to single spaces. Leading and trailing whitespace is also collapsed (becomes a single space at each end unless the input is already trimmed).

Example

str_collapse "foo   bar     baz"   # => "foo bar baz"
printf 'a  b\tc\n' | str_collapse  # => "a b c"

Arguments

  • ... (string): Text to collapse (may also be piped via stdin)

Exit codes

  • 0: Always

Output on stdout

  • String with consecutive whitespace reduced to single spaces