String

String (extern class)

The basic String class.

A Haxe String is immutable, it is not possible to modify individual characters. No method of this class changes the state of this String.

Strings can be constructed using the String literal syntax "string value".

String can be concatenated by using the + operator. If an operand is not a String, it is passed through Std.string() first.

See: https://haxe.org/manual/std-String.html

Static Members

fromCharCode(code: Int): String

Returns the String corresponding to the character code code.

If code is negative or has another invalid value, the result is unspecified.

Name Type
code Int
Returns
String

Instance Members

length: Int

The number of characters in this String.


toUpperCase(): String

Returns a String where all characters of this String are upper case.

Returns
String

toLowerCase(): String

Returns a String where all characters of this String are lower case.

Returns
String

charAt(index: Int): String

Returns the character at position index of this String.

If index is negative or exceeds this.length, the empty String "" is returned.

Name Type
index Int
Returns
String

charCodeAt(index: Int): Null<Int>

Returns the character code at position index of this String.

If index is negative or exceeds this.length, null is returned.

To obtain the character code of a single character, "x".code can be used instead to inline the character code at compile time. Note that this only works on String literals of length 1.

Name Type
index Int
Returns
Null<Int>

indexOf(str: String, ?startIndex: Int): Int

Returns the position of the leftmost occurrence of str within this String.

If startIndex is given, the search is performed within the substring of this String starting from startIndex.

If startIndex exceeds this.length, -1 is returned.

If startIndex is negative, the result is unspecifed.

Otherwise the search is performed within this String. In either case, the returned position is relative to the beginning of this String.

If str cannot be found, -1 is returned.

Name Type Default
str String
startIndex Int (optional)
Returns
Int

lastIndexOf(str: String, ?startIndex: Int): Int

Returns the position of the rightmost occurrence of str within this String.

If startIndex is given, the search is performed within the substring of this String from 0 to startIndex + str.length. Otherwise the search is performed within this String. In either case, the returned position is relative to the beginning of this String.

If startIndex is negative, the result is unspecifed.

If str cannot be found, -1 is returned.

Name Type Default
str String
startIndex Int (optional)
Returns
Int

split(delimiter: String): Array<String>

Splits this String at each occurrence of delimiter.

If this String is the empty String "", the result is not consistent across targets and may either be [] (on Js, Cpp) or [""].

If delimiter is the empty String "", this String is split into an Array of this.length elements, where the elements correspond to the characters of this String.

If delimiter is not found within this String, the result is an Array with one element, which equals this String.

If delimiter is null, the result is unspecified.

Otherwise, this String is split into parts at each occurrence of delimiter. If this String starts (or ends) with delimiter, the result Array contains a leading (or trailing) empty String "" element. Two subsequent delimiters also result in an empty String "" element.

Name Type
delimiter String
Returns
Array<String>

substr(pos: Int, ?len: Int): String

Returns len characters of this String, starting at position pos.

If len is omitted, all characters from position pos to the end of this String are included.

If pos is negative, its value is calculated from the end of this String by this.length + pos. If this yields a negative value, 0 is used instead.

If the calculated position + len exceeds this.length, the characters from that position to the end of this String are returned.

If len is negative, the result is unspecified.

Name Type Default
pos Int
len Int (optional)
Returns
String

substring(startIndex: Int, ?endIndex: Int): String

Returns the part of this String from startIndex to but not including endIndex.

If startIndex or endIndex are negative, 0 is used instead.

If startIndex exceeds endIndex, they are swapped.

If the (possibly swapped) endIndex is omitted or exceeds this.length, this.length is used instead.

If the (possibly swapped) startIndex exceeds this.length, the empty String "" is returned.

Name Type Default
startIndex Int
endIndex Int (optional)
Returns
String

toString(): String

Returns the String itself.

Returns
String

new(string: String): Void

Creates a copy from a given String.

Name Type
string String