String

Category: Built-In Types

Brief Description

Built-in string class.

Member Functions

String basename ( )
bool begins_with ( String text )
String c_escape ( )
String c_unescape ( )
String capitalize ( )
int casecmp_to ( String to )
bool empty ( )
String extension ( )
int find ( String what, int from=0 )
int find_last ( String what )
int findn ( String what, int from=0 )
String get_base_dir ( )
String get_file ( )
int hash ( )
int hex_to_int ( )
String insert ( int pos, String what )
bool is_abs_path ( )
bool is_rel_path ( )
bool is_valid_float ( )
bool is_valid_html_color ( )
bool is_valid_identifier ( )
bool is_valid_integer ( )
bool is_valid_ip_address ( )
String json_escape ( )
String left ( int pos )
int length ( )
bool match ( String expr )
bool matchn ( String expr )
RawArray md5_buffer ( )
String md5_text ( )
int nocasecmp_to ( String to )
int ord_at ( int at )
String pad_decimals ( int digits )
String pad_zeros ( int digits )
String percent_decode ( )
String percent_encode ( )
String plus_file ( String file )
String replace ( String what, String forwhat )
String replacen ( String what, String forwhat )
int rfind ( String what, int from=-1 )
int rfindn ( String what, int from=-1 )
String right ( int pos )
StringArray split ( String divisor, bool allow_empty=True )
RealArray split_floats ( String divisor, bool allow_empty=True )
String strip_edges ( bool left=True, bool right=True )
String substr ( int from, int len )
RawArray to_ascii ( )
float to_float ( )
int to_int ( )
String to_lower ( )
String to_upper ( )
RawArray to_utf8 ( )
String xml_escape ( )
String xml_unescape ( )

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

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.

Return a copy of the string with special characters escaped using the C language standard.

Return a copy of the string with escaped characters replaced by their meanings according to the C language standard.

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.

Return true if the string is empty.

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.

If the string is a path to a file, return the base directory.

If the string is a path to a file, return the file and ignore the base directory.

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.

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).

Return the MD5 hash of the string as an array of bytes.

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.

Decode a percent-encoded string. See 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.

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.

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.

Convert a string, containing a decimal number, into a float.

  • int to_int ( )

Convert a string, containing an integer number, into an int.

Return the string converted to lowercase.

Return the string converted to uppercase.

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().

Return a copy of the string with special characters escaped using the XML standard.

Return a copy of the string with escaped characters replaced by their meanings according to the XML standard.