String

Category: Built-In Types

Brief Description

Built-in string class.

Member Functions

String String ( bool from )
String String ( int from )
String String ( float from )
String String ( Vector2 from )
String String ( Rect2 from )
String String ( Vector3 from )
String String ( Matrix32 from )
String String ( Plane from )
String String ( Quat from )
String String ( AABB from )
String String ( Matrix3 from )
String String ( Transform from )
String String ( Color from )
String String ( NodePath from )
String String ( RID from )
String String ( InputEvent from )
String String ( Dictionary from )
String String ( Array from )
String String ( RawArray from )
String String ( IntArray from )
String String ( RealArray from )
String String ( StringArray from )
String String ( Vector2Array from )
String String ( Vector3Array from )
String String ( ColorArray from )
String basename ( )
bool begins_with ( String text )
StringArray bigrams ( )
String c_escape ( )
String c_unescape ( )
String capitalize ( )
int casecmp_to ( String to )
bool empty ( )
bool ends_with ( String text )
void erase ( int pos, int chars )
String extension ( )
int find ( String what, int from=0 )
int find_last ( String what )
int findn ( String what, int from=0 )
String format ( var values, String placeholder={_} )
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_subsequence_of ( String text )
bool is_subsequence_ofi ( String text )
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 )
RawArray sha256_buffer ( )
String sha256_text ( )
float similarity ( String text )
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

  • String String ( Matrix32 from )
  • String String ( Matrix3 from )
  • String String ( RawArray from )
  • String String ( IntArray from )
  • String String ( RealArray from )
  • String String ( StringArray from )
  • String String ( Vector2Array from )
  • String String ( Vector3Array from )
  • String String ( ColorArray from )

Return true if the strings begins with the given string.

Return the bigrams (pairs of consecutive letters) of this 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.

Return true if the strings ends with the given string.

  • void erase ( int pos, int chars )

Erase chars characters from the string starting from pos.

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 path to the file without the extension.

If the string is a path to a file, return the extension.

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

Check whether this string is a subsequence of the given string.

Check whether this string is a subsequence of the given string, without considering case.

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

Return the SHA-256 hash of the string as a string.

Return the similarity index of the text compared to this string. 1 means totally similar and 0 means totally dissimilar.

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