A SubString slice that cuts a multibyte (non-latin) character in half does not contain valid data. On current game versions such invalid slices are collapsed to a marker string with a constant string hash. Since this behavior is undocumented and has changed between game versions, the marker hash is computed at runtime from a known 2-byte character, so a future engine change degrades gracefully (multibyte detection turns off) instead of corrupting data. The historically observed hash 1843378377 is kept as an additional fallback.
public constant ENABLE_MULTIBYTE_SUPPORT = trueDeclaration shown above.
Configurable. Override it in your map’s config package.
public constant PARTIAL_CHAR_MARKER = "ä".substring(0, 1)public constant PARTIAL_CHAR_HASH = PARTIAL_CHAR_MARKER.getHash()public function string.isMultibytePartial() returns booleanReturns true if this string is an invalid slice of a multibyte character. Only meaningful when ENABLE_MULTIBYTE_SUPPORT is enabled.
public constant LEAD4_HASH = "😀".substring(0, 1).getHash()Hash of a slice containing only the lead byte of a 4-byte character (emoji and other astral plane chars). Current game versions collapse these to the partial char marker like any other lead byte, making this equal to PARTIAL_CHAR_HASH. It is kept as a fallback for versions that hash them per byte instead.
public function string.isCharBoundary(int pos) returns booleanReturns true if this string can be split at the given position without cutting a multibyte character in half, i.e. the byte at the given position starts a new character instead of continuing a preceding one. Positions at or outside the string’s bounds count as boundaries. Only meaningful when ENABLE_MULTIBYTE_SUPPORT is enabled.
public function string.isNotBlank() returns booleanReturns true if this string is non-null and not empty or only consisting of whitespace.
public function string.toCharsetInt() returns intreturns the position of the char in the charset therefore converting a single char into an int that can be converted back to a char with .toCharsetString()
public function string.toReal() returns realCreates a real from a string that only contains numbers (0-9) and a sign
public function string.toInt() returns intCreates an int from a string that only contains numbers (0-9) and a sign
public function int.toCharsetString() returns stringConverts an int to the representative char
public function string.substring(int start, int stop) returns stringreturns a substring specified by end and start position. Positions are byte offsets, so slicing a string containing multibyte (non-latin) characters can cut one in half. See string.isCharBoundary.
public function string.substring(int start) returns stringreturns a substring specified by end and start position. Positions are byte offsets, see string.substring(int, int).
public function string.length() returns intLength of the string in bytes. Multibyte (non-latin) characters count as 2-4 bytes each, so this is not the number of characters. Iterate the string to count those, e.g. for c in s.
public function string.charAt(int index) returns stringReturns the byte at the given position. 0 = first byte. This only returns a whole character for single byte (latin) characters, iterate the string instead to read multibyte characters.
public function string.toAbilityId() returns intConverts a string to an ability id
public function string.endsWith(string s) returns booleanReturns if the given string ends with the specified string.
public function string.startsWith(string s) returns booleanReturns if the given string starts with the specified string.
public function string.toLowerCase() returns stringReturns the string in lowercase letters
public function string.toUpperCase() returns stringReturns the string in uppercase letters
public function string.isUpper() returns booleanTrue when the string equals its uppercase form. Strings without letters (“”, digits, punctuation) are therefore also true.
public function string.isLower() returns booleanTrue when the string equals its lowercase form. Strings without letters (“”, digits, punctuation) are therefore also true.
public function string.trim() returns stringReturns the given string with whitespace (“ “, \n, \t, \r) removed from both ends
public function string.ltrim() returns stringReturns the given string with whitespace (“ “, \n, \t, \r) removed from the left end
public function string.rtrim() returns stringReturns the given string with whitespace (“ “, \n, \t, \r) removed from the right end
public function string.ltrim(string val) returns stringRemoves a string from the beginning of another string
public function string.rtrim(string val) returns stringRemoves a string from the end of another string
public function string.trim(string val) returns stringRemoves a string from both ends of another string
public function string.indexOf(string s) returns intReturns the index of the specified string inside the given string. If the string does not exist, the returnvalue is -1
public function string.indexOf(string s, int startpos) returns intReturns the index of the specified string inside the given string, starting the search at given startposition. If the string does not exist, the returnvalue is -1
public function string.lastIndexOf(string s) returns intReturns the last index of the specified string inside the given string, If the string does not exist, the returnvalue is -1
public function string.countOccurences(string findStr) returns intReturns the occurences of a certain string within a string. An empty string never occurs, the result is 0.
public function string.contains(string s) returns booleanTrue if the string contains the given string
public function string.isWhitespace() returns booleanReturns if the given string is a whitespace (“ “,\n,\t,\r)
public function string.firstUpper() returns stringReturns a new string with first letter is upper
public function string.firstLower() returns stringReturns a new string with first letter is lower
public function string.replace(string oldSubstring, string newSubstring) returns stringReturns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string
public function stringCompare(string s1, string s2) returns intReturns a negative number if s1 sorts before s2, a positive number if it sorts after, and 0 only if the two strings are equal.
Alphanumerics keep their long standing order: digits, then lowercase, then uppercase, so “Hello” sorts after “hello”. Every other printable ascii character sorts after all alphanumerics, ordered by ascii code point among themselves. Bytes outside printable ascii - control characters and the individual bytes of multibyte characters - sort last, tie-broken by string hash so the result stays consistent.
public function string.getHash() returns intpublic function string.format(vararg string replacements) returns stringFormats the given string replacing {x} delimiters with the passed replacements. Replacements are inserted in a single pass, so text inside a replacement is never substituted again. Delimiters without a matching replacement are left as they are. Example: “You got {0} gold”.format(goldAmount) *
public function string.iterator() returns StringIteratorIterates the string one character at a time. With ENABLE_MULTIBYTE_SUPPORT this yields whole multibyte (non-latin) characters, otherwise single bytes.
public function string.toLines() returns StringLines