API Reference › Unicode › Unicode.truncate
method

Unicode.truncate

Unicode.truncate(s, n) -> string

Returns the first n code points as a new string, never splitting a multibyte character — the safe way to cap a display name or a chat line to a length. If the string has fewer than n code points it is returned whole; n <= 0 yields the empty string.

Parameters

sthe UTF-8 string
nthe maximum number of code points to keep

Example

program Truncate {
  entry {
    if Unicode.truncate("hello", 3) == "hel" { print(1) }
  }
}
← All symbols