Skip to main content

string

Availability

Device + Agent

Description

The functionality of Squirrel’s string object is extended in two ways: the language’s own string library, which adds a series of standalone functions, and the data type’s delegate object, which provides a series of methods called using dot syntax. Both library and delegate provide tools for manipulating strings and the characters they contain.

Referencing

Strings are technically addressed by reference, but because they are also immutable, it is not possible to write code that can tell that strings behave differently from scalar values.

Known Issues

String Length

Device-side Squirrel does not deal correctly with strings longer than 65,535 bytes. No warnings or errors are currently generated, either at compile-time (for literals) or run-time (for constructed strings), but oversize strings behave as if their lengths were reduced modulo 65,536.

Workaround Check the lengths of strings likely to contain 65,535 Ascii characters (fewer if you use unicode) and segment into multiple strings as necessary.

Comparisons

If you attempt to use relative comparison operators, such as >, >=, <, <= or <=>, with strings that contain NUL characters (ie. bytes of value 0), then Squirrel will ignore any characters beyond the first NUL. For example:

local a = "r" + "\x00" + "a";
local b = "r" + "\x00" + "c";
server.log(b <=> a);

will display 0 because the two strings’ first characters are the same; the final characters come after NULs so are ignored.

This is not the case with equality comparison operators (!=, ==) — Squirrel includes any NULs present in the string in the comparison.

Further Information

For more guidance on using strings, please see the Squirrel Programming Guide.

Member Entities

The string object has the following member methods:

The string object has the following member functions:

  • format()Formats and returns a string for display
  • lstrip()Removes any whitespace from the left of a string
  • rstrip()Removes any whitespace from the right of a string
  • split()Divides the passed string into an array of sub-strings
  • strip()Removes any whitespace from the both ends of a string