cc.strings

Various utilities for working with strings and text.

See also

Changes

wrap(text [, width])Wraps a block of text, so that each line fits within the given width.
ensure_width(line [, width])Makes the input string a fixed width.
split(str, deliminator [, plain=false [, limit]])Split a string into parts, each separated by a deliminator.
wrap(text [, width])Source

Wraps a block of text, so that each line fits within the given width.

This may be useful if you want to wrap text before displaying it to a monitor or printer without using print.

Parameters

  1. text string The string to wrap.
  2. width? number The width to constrain to, defaults to the width of the terminal.

Returns

  1. { string... } The wrapped input string as a list of lines.

Usage

ensure_width(line [, width])Source

Makes the input string a fixed width. This either truncates it, or pads it with spaces.

Parameters

  1. line string The string to normalise.
  2. width? number The width to constrain to, defaults to the width of the terminal.

Returns

  1. string The string with a specific width.

Usage

split(str, deliminator [, plain=false [, limit]])Source

Split a string into parts, each separated by a deliminator.

For instance, splitting the string "a b c" with the deliminator " ", would return a table with three strings: "a", "b", and "c".

By default, the deliminator is given as a Lua pattern. Passing true to the plain argument will cause the deliminator to be treated as a litteral string.

Parameters

  1. str string The string to split.
  2. deliminator string The pattern to split this string on.
  3. plain? boolean = false Treat the deliminator as a plain string, rather than a pattern.
  4. limit? number The maximum number of elements in the returned list.

Returns

  1. { string... } The list of split strings.

Usage

See also

Changes

  • New in version 1.112.0