Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

String

A built-in type for strings.

Description

This is the built-in string Variant type (and the one used by GDScript). Strings may contain any number of Unicode characters, and expose methods useful for manipulating and generating strings. Strings are reference-counted and use a copy-on-write approach (every modification to a string returns a new String), so passing them around is cheap in resources.

Some string methods have corresponding variations. Variations suffixed with n (countn, findn, replacen, etc.) are case-insensitive (they make no distinction between uppercase and lowercase letters). Method variations prefixed with r (rfind, rsplit, etc.) are reversed, and start from the end of the string, instead of the beginning.

Note: In a boolean context, a string will evaluate to false if it is empty (""). Otherwise, a string will always evaluate to true. The not operator cannot be used. Instead, is_empty should be used to check for empty strings.

Note

There are notable differences when using this API with C#. See C# API differences to GDScript for more information.

Tutorials

Constructors

String

String ( )

String

String ( String from )

String

String ( NodePath from )

String

String ( StringName from )

Methods

bool

begins_with ( String text ) const

PackedStringArray

bigrams ( ) const

int

bin_to_int ( ) const

String

c_escape ( ) const

String

c_unescape ( ) const

String

capitalize ( ) const

int

casecmp_to ( String to ) const

String

chr ( int char ) static

bool

contains ( String what ) const

int

count ( String what, int from=0, int to=0 ) const

int

countn ( String what, int from=0, int to=0 ) const

String

dedent ( ) const

bool

ends_with ( String text ) const

String

erase ( int position, int chars=1 ) const

int

find ( String what, int from=0 ) const

int

findn ( String what, int from=0 ) const

String

format ( Variant values, String placeholder="{_}" ) const

String

get_base_dir ( ) const

String

get_basename ( ) const

String

get_extension ( ) const

String

get_file ( ) const

String

get_slice ( String delimiter, int slice ) const

int

get_slice_count ( String delimiter ) const

String

get_slicec ( int delimiter, int slice ) const

int

hash ( ) const

PackedByteArray

hex_decode ( ) const

int

hex_to_int ( ) const

String

humanize_size ( int size ) static

String

indent ( String prefix ) const

String

insert ( int position, String what ) const

bool

is_absolute_path ( ) const

bool

is_empty ( ) const

bool

is_relative_path ( ) const

bool

is_subsequence_of ( String text ) const

bool

is_subsequence_ofn ( String text ) const

bool

is_valid_filename ( ) const

bool

is_valid_float ( ) const

bool

is_valid_hex_number ( bool with_prefix=false ) const

bool

is_valid_html_color ( ) const

bool

is_valid_identifier ( ) const

bool

is_valid_int ( ) const

bool

is_valid_ip_address ( ) const

String

join ( PackedStringArray parts ) const

String

json_escape ( ) const

String

left ( int length ) const

int

length ( ) const

String

lpad ( int min_length, String character=" " ) const

String

lstrip (