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¶
字符串内置类型。
描述¶
这是内置的字符串 Variant 类型(GDScript 使用的就是这个类型)。字符串中可以包含任意数量的 Unicode 字符,暴露的方法可用于字符串的操作和生成。字符串有引用计数,使用写时复制技术(每次对字符串的修改都会返回新的 String),所以传递字符串的资源损耗很小。
部分字符串方法有对应的变体。后缀 n
的变体(countn、findn、replacen 等)大小写不敏感(不区分大写字符和小写字符)。前缀 r
的方法变体(rfind、rsplit 等)是逆序的,会从字符串末尾开始,而不是从开头开始。
注意:在布尔语境下,空字符串(""
)的求值结果为 false
。否则字符串的求值结果始终为 true
。无法使用 not
运算符。检查空字符串请使用 is_empty。
备注
通过 C# 使用该 API 时会有显著不同,详见 C# API 与 GDScript 的差异。
教程¶
构造函数¶
String() |
|
String(from: StringName) |
方法¶
begins_with(text: String) const |
|
bigrams() const |
|
bin_to_int() const |
|
c_escape() const |
|
c_unescape() const |
|
capitalize() const |
|
casecmp_to(to: String) const |
|
dedent() const |
|
filecasecmp_to(to: String) const |
|
filenocasecmp_to(to: String) const |
|
get_base_dir() const |
|
get_basename() const |
|
get_extension() const |
|
get_file() const |
|
get_slice_count(delimiter: String) const |
|
get_slicec(delimiter: int, slice: int) const |
|
hash() const |
|
hex_decode() const |
|
hex_to_int() const |
|
humanize_size(size: int) static |
|
is_absolute_path() const |
|
is_empty() const |
|
is_relative_path() const |
|
is_subsequence_of(text: String) const |
|
is_subsequence_ofn(text: String) const |
|
is_valid_filename() const |
|
is_valid_float() const |
|
is_valid_hex_number(with_prefix: bool = false) const |
|
is_valid_html_color() const |
|
is_valid_identifier() const |
|
is_valid_int() const |
|
is_valid_ip_address() const |
|
join(parts: PackedStringArray) const |
|
json_escape() const |
|
length() const |
|
md5_buffer() const |
|
md5_text() const |
|
naturalcasecmp_to(to: String) const |
|
naturalnocasecmp_to(to: String) const |
|
nocasecmp_to(to: String) const |
|
num_int64(number: int, base: int = 10, capitalize_hex: bool = false) static |
|
num_scientific(number: float) static |
|
num_uint64(number: int, base: int = 10, capitalize_hex: bool = false) static |
|
pad_decimals(digits: int) const |
|
reverse() const |
|
rsplit(delimiter: String = "", allow_empty: bool = true, maxsplit: int = 0) const |
|
sha1_buffer() const |
|
sha1_text() const |
|
sha256_buffer() const |
|
sha256_text() const |
|
similarity(text: String) const |
|
simplify_path() const |
|
split(delimiter: String = "", allow_empty: bool = true, maxsplit: int = 0) const |
|
split_floats(delimiter: String, allow_empty: bool = true) const |
|
strip_edges(left: bool = true, right: bool = true) const |
|
strip_escapes() const |
|
to_ascii_buffer() const |
|
to_camel_case() const |
|
to_float() const |
|
to_int() const |
|
to_lower() const |
|
to_pascal_case() const |
|
to_snake_case() const |
|
to_upper() const |
|
to_utf8_buffer() const |
|
to_utf16_buffer() const |
|
to_utf32_buffer() const |
|
to_wchar_buffer() const |
|
trim_prefix(prefix: String) const |
|
trim_suffix(suffix: String) const |
|
unicode_at(at: int) const |
|
uri_decode() const |
|
uri_encode() const |
|
validate_filename() const |
|
validate_node_name() const |
|
xml_escape(escape_quotes: bool = false) const |
|
xml_unescape() const |
运算符¶
operator !=(right: String) |
|
operator !=(right: StringName) |
|
operator %(right: Variant) |
|
operator +(right: String) |
|
operator +(right: StringName) |
|
operator <(right: String) |
|
operator <=(right: String) |
|
operator ==(right: String) |
|
operator ==(right: StringName) |
|
operator >(right: String) |
|
operator >=(right: String) |
|
operator [](index: int) |
构造函数说明¶
构造空的 String(""
)。
构造给定 String 的副本。
从给定的 NodePath 构造新的 String。
String String(from: StringName)