Skip to content

class_string

reduz edited this page Feb 23, 2014 · 11 revisions

String

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 necesary 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.
  • int casecmp_to ( String to ) \ Perform a case-sensitive comparison to antoher 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.
  • int find ( String what, int from=0 ) \ Find the first occurence of a substring, return the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed.
  • int find_last ( String what ) \ Find the last occurence of a substring, return the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed.
  • int findn ( String what, int from=0 ) \ Find the first occurence 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_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.
  • 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.
  • String left ( int pos ) \ Return an amount of characters from the left of the string.
  • int length ( ) \ Return the length of the string in characters.
  • bool match ( String expr ) \ Do a simple expression matching, using ? and * wildcards.
  • bool matchn ( String expr ) \ Do a simple, case insensitive, expression matching, using ? and * wildcards.
  • int nocasecmp_to ( String to ) \ Perform a case-insensitive comparison to antoher string, return -1 if less, 0 if equal and +1 if greater.
  • String replacen ( String what, String forwhat ) \ Replace occurrences of a substring for different ones inside the string, but search case-insensitive.
  • int rfind ( String what, int from=-1 ) \ Perform a search for a substring, but start from the end of the string instead of the begining.
  • int rfindn ( String what, int from=-1 ) \ Perform a search for a substring, but start from the end of the string instead of the begining. Also search case-insensitive.
  • String right ( int pos ) \ 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 ",".
  • RealArray split_floats ( String divisor, bool allow_empty=True ) \ 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 ",".
  • String strip_edges ( ) \ Return a copy of the string stripped of any non-printable character at the begining and the end.

Clone this wiki locally