String¶
Category: Built-In Types
Brief Description¶
Built-in string class.
Member Functions¶
Description¶
This is the built-in string class (and the one used by GDScript). It supports Unicode and provides all necessary means for string handling. Strings are reference counted and use a copy-on-write approach, so passing them around is cheap in resources.
Member Function Description¶
- String basename ( )
If the string is a path to a file, return the path to the file without the extension.
Return true if the strings begins with the given string.
- String c_escape ( )
Return a copy of the string with special characters escaped using the C language standard.
- String c_unescape ( )
Return a copy of the string with escaped characters replaced by their meanings according to the C language standard.
- String capitalize ( )
Change 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
.
Perform a case-sensitive comparison to another string, return -1 if less, 0 if equal and +1 if greater.
- bool empty ( )
Return true if the string is empty.
- String extension ( )
If the string is a path to a file, return the extension.
Find the first occurrence of a substring, return the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed.
Find the last occurrence of a substring, return the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed.
Find the first occurrence of a substring but search as case-insensitive, return the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed.
- String get_base_dir ( )
If the string is a path to a file, return the base directory.
- String get_file ( )
If the string is a path to a file, return the file and ignore the base directory.
- int hash ( )
Hash the string and return a 32 bits integer.
- int hex_to_int ( )
Convert a string containing an hexadecimal number into an int.
Insert a substring at a given position.
- bool is_abs_path ( )
If the string is a path to a file or directory, return true if the path is absolute.
- bool is_rel_path ( )
If the string is a path to a file or directory, return true if the path is relative.
- bool is_valid_float ( )
Check whether the string contains a valid float.
- bool is_valid_html_color ( )
Check whether the string contains a valid color in HTML notation.
- bool is_valid_identifier ( )
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.
- bool is_valid_integer ( )
Check whether the string contains a valid integer.
- bool is_valid_ip_address ( )
Check whether the string contains a valid IP address.
- String json_escape ( )
Return a copy of the string with special characters escaped using the JSON standard.
Return an amount of characters from the left of the string.
- int length ( )
Return the length of the string in characters.
Do a simple expression match, where ‘*’ matches zero or more arbitrary characters and ‘?’ matches any single character except ‘.’.
Do a simple case insensitive expression match, using ? and * wildcards (see match).
- RawArray md5_buffer ( )
Return the MD5 hash of the string as an array of bytes.
- String md5_text ( )
Return the MD5 hash of the string as a string.
Perform a case-insensitive comparison to another string, return -1 if less, 0 if equal and +1 if greater.
Return the character code at position at
.
Format a number to have an exact number of digits
after the decimal point.
Format a number to have an exact number of digits
before the decimal point.
- String percent_decode ( )
Decode a percent-encoded string. See percent_encode.
- String percent_encode ( )
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.
If the string is a path, this concatenates file
at the end of the string as a subpath. E.g. "this/is".plus_file("path") == "this/is/path"
.
Replace occurrences of a substring for different ones inside the string.
Replace occurrences of a substring for different ones inside the string, but search case-insensitive.
Perform a search for a substring, but start from the end of the string instead of the beginning.
Perform a search for a substring, but start from the end of the string instead of the beginning. Also search case-insensitive.
Return the right side of the string from a given position.
- StringArray split ( String divisor, bool allow_empty=True )
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 ”,”.
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 ”,”.
Return 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.
Return part of the string from the position from
, with length len
.
- RawArray to_ascii ( )
Convert the String (which is a character array) to RawArray (which is an array of bytes). The conversion is speeded up in comparison to to_utf8() with the assumption that all the characters the String contains are only ASCII characters.
- float to_float ( )
Convert a string, containing a decimal number, into a float
.
- int to_int ( )
Convert a string, containing an integer number, into an int
.
- String to_lower ( )
Return the string converted to lowercase.
- String to_upper ( )
Return the string converted to uppercase.
- RawArray to_utf8 ( )
Convert the String (which is an array of characters) to RawArray (which is an array of bytes). The conversion is a bit slower than to_ascii(), but supports all UTF-8 characters. Therefore, you should prefer this function over to_ascii().
- String xml_escape ( )
Return a copy of the string with special characters escaped using the XML standard.
- String xml_unescape ( )
Return a copy of the string with escaped characters replaced by their meanings according to the XML standard.