Extension methods to manipulate strings.
Static methods
staticbaseName(instance:String):String
If the string is a path to a file, return the path to the file without the extension.
@see godot.StringExtensions.getBaseDir
@see godot.StringExtensions.getFile
Parameters:
instance | The path to a file. |
---|
Returns:
The path to the file without the extension.
See also:
staticbeginsWith(instance:String, text:String):Bool
Returns true
if the strings begins
with the given string text
.
Parameters:
instance | The string to check. |
---|---|
text | The beginning string. |
Returns:
If the string begins with the given string.
staticinlinebigrams(instance:String):Array<String>
Returns the bigrams (pairs of consecutive letters) of this string.
Parameters:
instance | The string that will be used. |
---|
Returns:
The bigrams of this string.
staticbinToInt(instance:String):Int
Converts a string containing a binary number into an integer.
Binary strings can either be prefixed with 0b
or not,
and they can also start with a -
before the optional prefix.
Parameters:
instance | The string to convert. |
---|
Returns:
The converted string.
staticcEscape(instance:String):String
Returns a copy of the string with special characters escaped using the C language standard.
Parameters:
instance | The string to escape. |
---|
Returns:
The escaped string.
staticcUnescape(instance:String):String
Returns a copy of the string with escaped characters replaced by their meanings according to the C language standard.
Parameters:
instance | The string to unescape. |
---|
Returns:
The unescaped string.
staticcapitalize(instance:String):String
Changes the case of some letters. Replace underscores with spaces, convert all letters
to lowercase then capitalize first and every letter following the space character.
For capitalize camelCase mixed_with_underscores
it will return
Capitalize Camelcase Mixed With Underscores
.
Parameters:
instance | The string to capitalize. |
---|
Returns:
The capitalized string.
staticcasecmpTo(instance:String, to:String):Int
Performs a case-sensitive comparison to another string, return -1 if less, 0 if equal and +1 if greater.
@see godot.StringExtensions.compareTo
Parameters:
instance | The string to compare. |
---|---|
to | The other string to compare. |
Returns:
-1 if less, 0 if equal and +1 if greater.
See also:
staticcompareTo(instance:String, to:String, ?caseSensitive:Bool):Int
Performs a comparison to another string, return -1 if less, 0 if equal and +1 if greater.
Parameters:
instance | The string to compare. |
---|---|
to | The other string to compare. |
caseSensitive | If |
Returns:
-1 if less, 0 if equal and +1 if greater.
staticcount(instance:String, what:String, ?caseSensitive:Bool, ?from:Int, ?to:Int):Int
Returns the amount of substrings what
in the string.
Parameters:
instance | The string where the substring will be searched. |
---|---|
what | The substring that will be counted. |
caseSensitive | If the search is case sensitive. |
from | Index to start searching from. |
to | Index to stop searching at. |
Returns:
Amount of substrings in the string.
staticendsWith(instance:String, text:String):Bool
Returns true
if the strings ends
with the given string text
.
Parameters:
instance | The string to check. |
---|---|
text | The ending string. |
Returns:
If the string ends with the given string.
staticextension(instance:String):String
Returns the extension without the leading period character (.
)
if the string is a valid file name or path. If the string does not contain
an extension, returns an empty string instead.
GD.Print("/path/to/file.txt".GetExtension()) // "txt"
GD.Print("file.txt".GetExtension()) // "txt"
GD.Print("file.sample.txt".GetExtension()) // "txt"
GD.Print(".txt".GetExtension()) // "txt"
GD.Print("file.txt.".GetExtension()) // "" (empty string)
GD.Print("file.txt..".GetExtension()) // "" (empty string)
GD.Print("txt".GetExtension()) // "" (empty string)
GD.Print("".GetExtension()) // "" (empty string)
@see godot.StringExtensions.getBaseDir
@see godot.StringExtensions.getFile
Parameters:
instance | The path to a file. |
---|
Returns:
The extension of the file or an empty string.
See also:
staticfind(instance:String, what:String, ?from:Int, ?caseSensitive:Bool):Int
staticFind(instance:String, what:Char16, ?from:Int, ?caseSensitive:Bool):Int
Find the first occurrence of a substring. Optionally, the search starting position can be passed.
Parameters:
instance | The string that will be searched. |
---|---|
what | The substring to find. |
from | The search starting position. |
caseSensitive | If |
Returns:
The starting position of the substring, or -1 if not found.
staticfindLast(instance:String, what:String, ?caseSensitive:Bool):Int
staticFindLast(instance:String, what:String, from:Int, ?caseSensitive:Bool):Int
Find the last occurrence of a substring.@see godot.StringExtensions.find
@see godot.StringExtensions.find
@see godot.StringExtensions.findLast
@see godot.StringExtensions.findN
Parameters:
instance | The string that will be searched. |
---|---|
what | The substring to find. |
caseSensitive | If |
Returns:
The starting position of the substring, or -1 if not found.
staticfindN(instance:String, what:String, ?from:Int):Int
Find the first occurrence of a substring but search as case-insensitive.
Optionally, the search starting position can be passed.
@see godot.StringExtensions.find
@see godot.StringExtensions.findLast
@see godot.StringExtensions.findLast
Parameters:
instance | The string that will be searched. |
---|---|
what | The substring to find. |
from | The search starting position. |
Returns:
The starting position of the substring, or -1 if not found.
See also:
staticgetBaseDir(instance:String):String
If the string is a path to a file, return the base directory.
@see godot.StringExtensions.extension
@see godot.StringExtensions.getFile
Parameters:
instance | The path to a file. |
---|
Returns:
The base directory.
See also:
staticgetFile(instance:String):String
If the string is a path to a file, return the file and ignore the base directory.
@see godot.StringExtensions.extension
@see godot.StringExtensions.getBaseDir
Parameters:
instance | The path to a file. |
---|
Returns:
The file name.
See also:
staticgetStringFromASCII(bytes:HaxeArray<UInt8>):String
Converts the given byte array of ASCII encoded text to a string.
Faster alternative to godot.StringExtensions.getStringFromUTF8
if the
content is ASCII-only. Unlike the UTF-8 function this function
maps every byte to a character in the array. Multibyte sequences
will not be interpreted correctly. For parsing user input always
use godot.StringExtensions.getStringFromUTF8
.
Parameters:
bytes | A byte array of ASCII characters (on the range of 0-127). |
---|
Returns:
A string created from the bytes.
staticgetStringFromUTF8(bytes:HaxeArray<UInt8>):String
Converts the given byte array of UTF-8 encoded text to a string.
Slower than godot.StringExtensions.getStringFromASCII
but supports UTF-8
encoded data. Use this function if you are unsure about the
source of the data. For user input this function
should always be preferred.
Parameters:
bytes | A byte array of UTF-8 characters (a character may take up multiple bytes). |
---|
Returns:
A string created from the bytes.
statichash(instance:String):UInt
Hash the string and return a 32 bits unsigned integer.
Parameters:
instance | The string to hash. |
---|
Returns:
The calculated hash of the string.
statichexEncode(bytes:HaxeArray<UInt8>):String
Returns a hexadecimal representation of this byte array as a string.
Parameters:
bytes | The byte array to encode. |
---|
Returns:
The hexadecimal representation of this byte array.
statichexToInt(instance:String):Int
Converts a string containing a hexadecimal number into an integer.
Hexadecimal strings can either be prefixed with 0x
or not,
and they can also start with a -
before the optional prefix.
Parameters:
instance | The string to convert. |
---|
Returns:
The converted string.
staticinsert(instance:String, pos:Int, what:String):String
Inserts a substring at a given position.
Parameters:
instance | The string to modify. |
---|---|
pos | Position at which to insert the substring. |
what | Substring to insert. |
Returns:
The string with what
inserted at the given
position pos
.
staticisAbsPath(instance:String):Bool
Returns true
if the string is a path to a file or
directory and its starting point is explicitly defined. This includes
res://
, user://
, C:\
, /
, etc.
Parameters:
instance | The string to check. |
---|
Returns:
If the string is an absolute path.
See also:
staticisRelPath(instance:String):Bool
Returns true
if the string is a path to a file or
directory and its starting point is implicitly defined within the
context it is being used. The starting point may refer to the current
directory (./
), or the current godot.Node
.
Parameters:
instance | The string to check. |
---|
Returns:
If the string is a relative path.
See also:
staticisSubsequenceOf(instance:String, text:String, ?caseSensitive:Bool):Bool
Check whether this string is a subsequence of the given string.
Parameters:
instance | The subsequence to search. |
---|---|
text | The string that contains the subsequence. |
caseSensitive | If |
Returns:
If the string is a subsequence of the given string.
See also:
staticisSubsequenceOfI(instance:String, text:String):Bool
Check whether this string is a subsequence of the given string, ignoring case differences.
Parameters:
instance | The subsequence to search. |
---|---|
text | The string that contains the subsequence. |
Returns:
If the string is a subsequence of the given string.
See also:
staticisValidFloat(instance:String):Bool
Check whether the string contains a valid float
.
Parameters:
instance | The string to check. |
---|
Returns:
If the string contains a valid floating point number.
staticisValidHtmlColor(instance:String):Bool
Check whether the string contains a valid color in HTML notation.
Parameters:
instance | The string to check. |
---|
Returns:
If the string contains a valid HTML color.
staticisValidIPAddress(instance:String):Bool
Check whether the string contains a valid IP address.
Parameters:
instance | The string to check. |
---|
Returns:
If the string contains a valid IP address.
staticisValidIdentifier(instance:String):Bool
Check whether the string is a valid identifier. As is common in programming languages, a valid identifier may contain only letters, digits and underscores (_) and the first character may not be a digit.
Parameters:
instance | The string to check. |
---|
Returns:
If the string contains a valid identifier.
staticisValidInteger(instance:String):Bool
Check whether the string contains a valid integer.
Parameters:
instance | The string to check. |
---|
Returns:
If the string contains a valid integer.
staticjSONEscape(instance:String):String
Returns a copy of the string with special characters escaped using the JSON standard.
Parameters:
instance | The string to escape. |
---|
Returns:
The escaped string.
staticlStrip(instance:String, chars:String):String
Returns a copy of the string with characters removed from the left.
Parameters:
instance | The string to remove characters from. |
---|---|
chars | The characters to be removed. |
Returns:
A copy of the string with characters removed from the left.
See also:
staticleft(instance:String, pos:Int):String
Returns an amount of characters from the left of the string.
Parameters:
instance | The original string. |
---|---|
pos | The position in the string where the left side ends. |
Returns:
The left side of the string from the given position.
See also:
staticlength(instance:String):Int
Returns the length of the string in characters.
Parameters:
instance | The string to check. |
---|
Returns:
The length of the string.
staticinlinemD5Buffer(instance:String):Array<UInt8>
Returns the MD5 hash of the string as an array of bytes.
Parameters:
instance | The string to hash. |
---|
Returns:
The MD5 hash of the string.
See also:
staticmD5Text(instance:String):String
Returns the MD5 hash of the string as a string.
Parameters:
instance | The string to hash. |
---|
Returns:
The MD5 hash of the string.
See also:
staticmatch(instance:String, expr:String, ?caseSensitive:Bool):Bool
Do a simple case sensitive expression match, using ? and * wildcards
(see godot.StringExtensions.exprMatch
).
Parameters:
instance | The string to check. |
---|---|
expr | Expression to check. |
caseSensitive | If |
Returns:
If the expression has any matches.
See also:
staticmatchN(instance:String, expr:String):Bool
Do a simple case insensitive expression match, using ? and * wildcards
(see godot.StringExtensions.exprMatch
).
Parameters:
instance | The string to check. |
---|---|
expr | Expression to check. |
Returns:
If the expression has any matches.
See also:
staticnocasecmpTo(instance:String, to:String):Int
Perform a case-insensitive comparison to another string, return -1 if less, 0 if equal and +1 if greater.
@see godot.StringExtensions.compareTo
Parameters:
instance | The string to compare. |
---|---|
to | The other string to compare. |
Returns:
-1 if less, 0 if equal and +1 if greater.
See also:
staticordAt(instance:String, at:Int):Int
Returns the character code at position at
.
Parameters:
instance | The string to check. |
---|---|
at | The position int the string for the character to check. |
Returns:
The character code.
staticpadDecimals(instance:String, digits:Int):String
Format a number to have an exact number of digits
after the decimal point.
Parameters:
instance | The string to pad. |
---|---|
digits | Amount of digits after the decimal point. |
Returns:
The string padded with zeroes.
See also:
staticpadZeros(instance:String, digits:Int):String
Format a number to have an exact number of digits
before the decimal point.
Parameters:
instance | The string to pad. |
---|---|
digits | Amount of digits before the decimal point. |
Returns:
The string padded with zeroes.
See also:
staticpercentDecode(instance:String):String
Decode a percent-encoded string. See godot.StringExtensions.percentEncode
.
staticpercentEncode(instance:String):String
Percent-encode a string. This is meant to encode parameters in a URL when sending a HTTP GET request and bodies of form-urlencoded POST request.
See also:
staticplusFile(instance:String, file:String):String
If the string is a path, this concatenates file
at the end of the string as a subpath.
E.g. "this/is".PlusFile("path") == "this/is/path"
.
Parameters:
instance | The path that will be concatenated. |
---|---|
file | File name to concatenate with the path. |
Returns:
The concatenated path with the given file name.
staticrFind(instance:String, what:String, ?from:Int):Int
Perform a search for a substring, but start from the end of the string instead of the beginning.
Parameters:
instance | The string that will be searched. |
---|---|
what | The substring to search in the string. |
from | The position at which to start searching. |
Returns:
The position at which the substring was found, or -1 if not found.
See also:
staticrFindN(instance:String, what:String, ?from:Int):Int
Perform a search for a substring, but start from the end of the string instead of the beginning. Also search case-insensitive.
Parameters:
instance | The string that will be searched. |
---|---|
what | The substring to search in the string. |
from | The position at which to start searching. |
Returns:
The position at which the substring was found, or -1 if not found.
See also:
staticrStrip(instance:String, chars:String):String
Returns a copy of the string with characters removed from the right.
Parameters:
instance | The string to remove characters from. |
---|---|
chars | The characters to be removed. |
Returns:
A copy of the string with characters removed from the right.
See also:
staticreplace(instance:String, what:String, forwhat:String):String
Replace occurrences of a substring for different ones inside the string.
Parameters:
instance | The string to modify. |
---|---|
what | The substring to be replaced in the string. |
forwhat | The substring that replaces |
Returns:
The string with the substring occurrences replaced.
See also:
staticreplaceN(instance:String, what:String, forwhat:String):String
Replace occurrences of a substring for different ones inside the string, but search case-insensitive.
Parameters:
instance | The string to modify. |
---|---|
what | The substring to be replaced in the string. |
forwhat | The substring that replaces |
Returns:
The string with the substring occurrences replaced.
See also:
staticright(instance:String, pos:Int):String
Returns the right side of the string from a given position.
Parameters:
instance | The original string. |
---|---|
pos | The position in the string from which the right side starts. |
Returns:
The right side of the string from the given position.
See also:
staticinlinesHA256Buffer(instance:String):Array<UInt8>
Returns the SHA-256 hash of the string as an array of bytes.
Parameters:
instance | The string to hash. |
---|
Returns:
The SHA-256 hash of the string.
See also:
staticsHA256Text(instance:String):String
Returns the SHA-256 hash of the string as a string.
Parameters:
instance | The string to hash. |
---|
Returns:
The SHA-256 hash of the string.
See also:
staticsimilarity(instance:String, text:String):Single
Returns the similarity index of the text compared to this string. 1 means totally similar and 0 means totally dissimilar.
Parameters:
instance | The string to compare. |
---|---|
text | The other string to compare. |
Returns:
The similarity index.
staticinlinesplit(instance:String, divisor:String, ?allowEmpty:Bool):Array<String>
Split the string by a divisor string, return an array of the substrings. Example "One,Two,Three" will return ["One","Two","Three"] if split by ",".
Parameters:
instance | The string to split. |
---|---|
divisor | The divisor string that splits the string. |
allowEmpty | If |
Returns:
The array of strings split from the string.
See also:
staticinlinesplitFloats(instance:String, divisor:String, ?allowEmpty:Bool):Array<Single>
Split the string in floats by using a divisor string, return an array of the substrings. Example "1,2.5,3" will return [1,2.5,3] if split by ",".
Parameters:
instance | The string to split. |
---|---|
divisor | The divisor string that splits the string. |
allowEmpty | If |
Returns:
The array of floats split from the string.
See also:
staticstripEdges(instance:String, ?left:Bool, ?right:Bool):String
Returns a copy of the string stripped of any non-printable character at the beginning and the end. The optional arguments are used to toggle stripping on the left and right edges respectively.
Parameters:
instance | The string to strip. |
---|---|
left | If the left side should be stripped. |
right | If the right side should be stripped. |
Returns:
The string stripped of any non-printable characters.
staticsubstr(instance:String, from:Int, len:Int):String
Returns part of the string from the position from
, with length len
.
Parameters:
instance | The string to slice. |
---|---|
from | The position in the string that the part starts from. |
len | The length of the returned part. |
Returns:
Part of the string from the position from
, with length len
.
staticinlinetoAscii(instance:String):Array<UInt8>
Converts the String (which is a character array) to PoolByteArray (which is an array of bytes).
The conversion is speeded up in comparison to godot.StringExtensions.toUTF8
with the assumption
that all the characters the String contains are only ASCII characters.
Parameters:
instance | The string to convert. |
---|
Returns:
The string as ASCII encoded bytes.
See also:
statictoFloat(instance:String):Single
Converts a string, containing a decimal number, into a float
.
Parameters:
instance | The string to convert. |
---|
Returns:
The number representation of the string.
See also:
statictoInt(instance:String):Int
Converts a string, containing an integer number, into an int
.
Parameters:
instance | The string to convert. |
---|
Returns:
The number representation of the string.
See also:
statictoLower(instance:String):String
Returns the string converted to lowercase.
Parameters:
instance | The string to convert. |
---|
Returns:
The string converted to lowercase.
See also:
staticinlinetoUTF8(instance:String):Array<UInt8>
Converts the String (which is an array of characters) to PoolByteArray (which is an array of bytes).
The conversion is a bit slower than godot.StringExtensions.toAscii
, but supports all UTF-8 characters.
Therefore, you should prefer this function over godot.StringExtensions.toAscii
.
Parameters:
instance | The string to convert. |
---|
Returns:
The string as UTF-8 encoded bytes.
See also:
statictoUpper(instance:String):String
Returns the string converted to uppercase.
Parameters:
instance | The string to convert. |
---|
Returns:
The string converted to uppercase.
See also:
staticxMLEscape(instance:String):String
Returns a copy of the string with special characters escaped using the XML standard.
Parameters:
instance | The string to escape. |
---|
Returns:
The escaped string.
See also:
staticxMLUnescape(instance:String):String
Returns a copy of the string with escaped characters replaced by their meanings according to the XML standard.
Parameters:
instance | The string to unescape. |
---|
Returns:
The unescaped string.
See also: