StringUtils

Utilities View source
StringUtils

Returns the width of the string. Only meaningful for single byte (latin) characters. Each byte of a multibyte (non-latin) character is looked up individually and falls back to the width of a space, so the result for non-latin text is an approximation rather than a true width.

Types

Functions and constants

public function texttag.center(vec3 pos, string message, real size) returns texttag
public function createCenteredTexttag(vec3 pos, string message, real size) returns texttag
public function string.getWidth() returns int
public function char(string s) returns char
public function char.toString() returns string
public function char.toInt() returns int
public function char.getWidth() returns int
public function string.toChar() returns char
public function string.toCharList() returns LinkedList<char>

Splits the string into chars. Only valid for single byte (latin) characters, multibyte characters are split into their individual bytes.

public function int.toChar() returns char
public function charToIndex(char c) returns int
public function charFromIndex(int index) returns char
public function string.split(string splitBy) returns LinkedList<string>

Splits the string by another string “this..is..an..example” split by the string “..” splits into a list containing four strings [“this”, “is”, “an”, “example”] An empty delimiter returns the original string as one field.

public function string.splitToArray(string delimiter) returns ArrayList<string>

Splits into specialized contiguous storage, preserving empty and trailing fields. An empty delimiter returns the original string as one field. The caller owns the list.

public function string.reduce(string reduced) returns string

Replaces consecutive repeats of the same string with a single instance Turns “strstr” into “str”

public function string.reduce() returns string

Replaces consecutive repeats of the whitespace character with a single instance Turns “ “ into “ “

public function string.forEachIn(string delim, ForStringSplitCallback cb)

Custom Function which can split strings and runs callback for each string. It can run even with no delimiter present (with single element). Example usage: “H001,H002”.forEachIn(“,”) -> doSomething()

public function string.isNumber() returns bool

Checks whether a string is a decimal number: an optional leading “-“, at least one digit, and at most one decimal point. “”, “-“, “.” and “-.” are not numbers.

public function string.isValidDescription() returns bool

Checks whether a string is valid in terms of max WC3 string length for various usages (Ability Description, Quest Description,…).

public function string.replaceChars(string charset, string replacementChar) returns string

Replaces all occurences of any character from given charlist by a given replacement string. Single pass: replacement text is never scanned again, so “ab”.replaceChars(“ab”, “ba”) is “baba”.