Hatch Game Engine Documentation v1.4.0
The documentation for the Hatch Game Engine
Loading...
Searching...
No Matches
String Class Reference

String manipulation functions. More...

Public Member Functions

string Format (string string, value values)
 Formats a format string according to the given format specifiers. A format specifier is a string of the form.
array Split (string string, integer delimiter)
 Splits a string by a delimiter.
integer CharAt (string string, integer index)
 Gets the 8-bit value of the character at the specified index.
integer CodepointAt (string string, integer index)
 Gets the codepoint value of the character at the specified index.
integer Length (string string)
 Gets the length of the string value.
integer Compare (string stringA, string stringB)
 Compares two strings lexicographically.
integer IndexOf (string string, string substring)
 Get the first index at which the substring occurs in the string.
boolean Contains (string string, string substring)
 Searches for whether a substring is within a string value.
string Substring (string string, integer startIndex, integer length)
 Get a string value from a portion of a larger string value.
string ToUpperCase (string string)
 Convert a string value to its uppercase representation.
string ToLowerCase (string string)
 Convert a string value to its lowercase representation.
integer LastIndexOf (string string, string substring)
 Get the last index at which the substring occurs in the string.
integer ParseInteger (string string, integer radix)
 Converts a string value to an integer value, if possible.
decimal ParseDecimal (string string)
 Convert a string value to a decimal value if possible.
array GetCodepoints (string string)
 Gets a list of UCS codepoints from UTF-8 text.
string FromCodepoints (array codepoints)
 Creates UTF-8 text from a list of UCS codepoints.

Detailed Description

String manipulation functions.

Member Function Documentation

◆ CharAt()

integer String.CharAt ( string string,
integer index )

Gets the 8-bit value of the character at the specified index.

Parameters
stringThe string containing the character.
indexThe character index to check.
Returns
Returns the value as an integer.

◆ CodepointAt()

integer String.CodepointAt ( string string,
integer index )

Gets the codepoint value of the character at the specified index.

Parameters
stringThe string containing the character.
indexThe character index to check.
Returns
Returns the value as an integer.

◆ Compare()

integer String.Compare ( string stringA,
string stringB )

Compares two strings lexicographically.

Parameters
stringAThe first string to compare.
stringBThe second string to compare.
Returns
Returns the comparison result as an integer. The return value is a negative integer if stringA appears before stringB lexicographically, a positive integer if stringA appears after stringB lexicographically, and zero if stringA and stringB are equal.

◆ Contains()

boolean String.Contains ( string string,
string substring )

Searches for whether a substring is within a string value.

Parameters
stringThe string to compare.
substringThe substring to search for.
Returns
Returns a boolean value.

◆ Format()

string String.Format ( string string,
value values )

Formats a format string according to the given format specifiers. A format specifier is a string of the form.

%[flags][width][.precision][conversion specifier]

where a conversion specifier must be one of the following:

  • d: Integers
  • f or F: Decimals
  • s: Strings
  • c: Characters
  • x or X: Hexadecimal integers
  • b or b: Binary integers
  • o: Octal integers
  • %: A literal percent sign character

Flags are optional, and must be one of the following:

  • 0: Pads the value with leading zeroes. See the width sub-specifier.
  • -: Left-justifies the result. See the width sub-specifier.
  • #: Prefixes something to the value depending on the conversion specifier:
    • x or X: Prefixes the value with 0x or 0X respectively.
    • b or B: Prefixes the value with 0b or 0B respectively.
    • f: Prefixes the value with a . character.
    • o: Prefixes the value with a 0 character.
  • +: Prefixes positive numbers with a plus sign.
  • A space character: If no sign character (- or +) was written, a space character is written instead.

A width sub-specifier is used in conjunction with the flags:

  • A number: The amount of padding to add.
  • *: This functions the same as the above, but the width is given in the next argument as an Integer value.

Precision specifiers are also supported:

  • . followed by a number:
    • For Integer values, this pads the value with leading zeroes.
    • For Decimal values, this specifies the number of digits to be printed after the decimal point (which is 6 by default).
    • For String values, this is the maximum amount of characters to be printed.
  • . followed by a *: This functions the same as the above, but the precision is given in the next argument as an Integer value.
Parameters
stringThe format string.
valuesVariable arguments.
Returns
Returns a string value.

◆ FromCodepoints()

string String.FromCodepoints ( array codepoints)

Creates UTF-8 text from a list of UCS codepoints.

Parameters
codepointsAn array of integer values.
Returns
Returns a string value.

◆ GetCodepoints()

array String.GetCodepoints ( string string)

Gets a list of UCS codepoints from UTF-8 text.

Parameters
stringThe UTF-8 string.
Returns
Returns an array of Integer values.

◆ IndexOf()

integer String.IndexOf ( string string,
string substring )

Get the first index at which the substring occurs in the string.

Parameters
stringThe string to compare.
substringThe substring to search for.
Returns
Returns the index as an integer.

◆ LastIndexOf()

integer String.LastIndexOf ( string string,
string substring )

Get the last index at which the substring occurs in the string.

Parameters
stringThe string to compare.
substringThe substring to search for.
Returns
Returns the index as an integer.

◆ Length()

integer String.Length ( string string)

Gets the length of the string value.

Parameters
stringThe input string.
Returns
Returns the length of the string value as an integer.

◆ ParseDecimal()

decimal String.ParseDecimal ( string string)

Convert a string value to a decimal value if possible.

Parameters
stringThe string to parse.
Returns
Returns the value as a decimal.

◆ ParseInteger()

integer String.ParseInteger ( string string,
integer radix )

Converts a string value to an integer value, if possible.

Parameters
stringThe string to parse.
radixThe numerical base, or radix. If 0, the radix is detected by the value of string:
If string begins with 0x, it is a hexadecimal number (base 16);
Else, if string begins with 0, it is an octal number (base 8);
Else, if string begins with 0b, it is a binary number (base 2);
Else, the number is assumed to be in base 10.
Returns
Returns the value as an integer.

◆ Split()

array String.Split ( string string,
integer delimiter )

Splits a string by a delimiter.

Parameters
stringThe string to split.
delimiterThe delimiter string.
Returns
Returns an array of string values.

◆ Substring()

string String.Substring ( string string,
integer startIndex,
integer length )

Get a string value from a portion of a larger string value.

Parameters
stringThe input string.
startIndexThe starting index of the substring.
lengthThe length of the substring.
Returns
Returns a string value.

◆ ToLowerCase()

string String.ToLowerCase ( string string)

Convert a string value to its lowercase representation.

Parameters
stringThe string to make lowercase.
Returns
Returns a lowercase string value.

◆ ToUpperCase()

string String.ToUpperCase ( string string)

Convert a string value to its uppercase representation.

Parameters
stringThe string to make uppercase.
Returns
Returns a uppercase string value.