Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
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.
備註
There are notable differences when using this API with C#. See C# API 與 GDScript 的不同 for more information.
Tutorials¶
Constructors¶
String ( ) |
|
String ( StringName from ) |
Methods¶
begins_with ( String text ) const |
|
bigrams ( ) const |
|
bin_to_int ( ) const |
|
c_escape ( ) const |
|
c_unescape ( ) const |
|
capitalize ( ) const |
|
casecmp_to ( String to ) const |
|
dedent ( ) const |
|
get_base_dir ( ) const |
|
get_basename ( ) const |
|
get_extension ( ) const |
|
get_file ( ) const |
|
get_slice_count ( String delimiter ) const |
|
get_slicec ( int delimiter, int slice ) const |
|
hash ( ) const |
|
hex_decode ( ) const |
|
hex_to_int ( ) const |
|
humanize_size ( int size ) static |
|
is_absolute_path ( ) const |
|
is_empty ( ) const |
|
is_relative_path ( ) const |
|
is_subsequence_of ( String text ) const |
|
is_subsequence_ofn ( String text ) const |
|
is_valid_filename ( ) const |
|
is_valid_float ( ) const |
|
is_valid_hex_number ( bool with_prefix=false ) const |
|
is_valid_html_color ( ) const |
|
is_valid_identifier ( ) const |
|
is_valid_int ( ) const |
|
is_valid_ip_address ( ) const |
|
join ( PackedStringArray parts ) const |
|
json_escape ( ) const |
|
length ( ) const |
|
md5_buffer ( ) const |
|
md5_text ( ) const |
|
naturalcasecmp_to ( String to ) const |
|
naturalnocasecmp_to ( String to ) const |
|
nocasecmp_to ( String to ) const |
|
num_int64 ( int number, int base=10, bool capitalize_hex=false ) static |
|
num_scientific ( float number ) static |
|
num_uint64 ( int number, int base=10, bool capitalize_hex=false ) static |
|
pad_decimals ( int digits ) const |
|
reverse ( ) const |
|
rsplit ( String delimiter="", bool allow_empty=true, int maxsplit=0 ) const |
|
sha1_buffer ( ) const |
|
sha1_text ( ) const |
|
sha256_buffer ( ) const |
|