类别: 内置类型

简要说明

内置字符串类。

方法

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 ( Transform2D from )

String

String ( Plane from )

String

String ( Quat from )

String

String ( AABB from )

String

String ( Basis from )

String

String ( Transform from )

String

String ( Color from )

String

String ( NodePath from )

String

String ( RID from )

String

String ( Dictionary from )

String

String ( Array from )

String

String ( PoolByteArray from )

String

String ( PoolIntArray from )

String

String ( PoolRealArray from )

String

String ( PoolStringArray from )

String

String ( PoolVector2Array from )

String

String ( PoolVector3Array from )

String

String ( PoolColorArray from )

bool

begins_with ( String text )

PoolStringArray

bigrams ( )

String

c_escape ( )

String

c_unescape ( )

String

capitalize ( )

int

casecmp_to ( String to )

int

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

int

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

String

dedent ( )

bool

empty ( )

bool

ends_with ( String text )

无效

erase ( int position, int chars )

int

find ( String what, int from=0 )

int

find_last ( String what )

int

findn ( String what, int from=0 )

String

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

String

get_base_dir ( )

String

get_basename ( )

String

get_extension ( )

String

get_file ( )

int

hash ( )

int

hex_to_int ( )

String

http_escape ( )

String

http_unescape ( )

String

insert ( int position, 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_filename ( )

bool

is_valid_float ( )

bool

is_valid_hex_number ( bool with_prefix=False )

bool

is_valid_html_color ( )

bool

is_valid_identifier ( )

bool

is_valid_integer ( )

bool

is_valid_ip_address ( )

String

json_escape ( )

String

left ( int position )

int

length ( )

String

lstrip ( String chars )

bool

match ( String expr )

bool

matchn ( String expr )

PoolByteArray

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 position )

PoolStringArray

rsplit ( String delimiter, bool allow_empty=True, int maxsplit=0 )

String

rstrip ( String chars )

PoolByteArray

sha1_buffer ( )

String

sha1_text ( )

PoolByteArray

sha256_buffer ( )

String

sha256_text ( )

float

similarity ( String text )

PoolStringArray

split ( String delimiter, bool allow_empty=True, int maxsplit=0 )

PoolRealArray

split_floats ( String delimiter, bool allow_empty=True )

String

strip_edges ( bool left=True, bool right=True )

String

strip_escapes ( )

String

substr ( int from, int len=-1 )

PoolByteArray

to_ascii ( )

float

to_float ( )

int

to_int ( )

String

to_lower ( )

String

to_upper ( )

PoolByteArray

to_utf8 ( )

String

trim_prefix ( String prefix )

String

trim_suffix ( String suffix )

String

xml_escape ( )

String

xml_unescape ( )

描述

这是内置的字符串类(也是gdscript使用的类)。它支持Unicode并为字符串处理提供所有必要的方法。字符串被引用计数并使用copy-on-write方法,因此传递它们在资源上是便宜的。

方法说明

从给定的 bool .

从给定的 int .

从给定的 float .

从给定的 Vector2 .

从给定的 Rect2 .

从给定的 Vector3 .

从给定的 Transform2D .

从给定的 Plane .

从给定的 Quat .

从给定的 AABB .

从给定的 Basis .

从给定的 Transform .

从给定的 Color .

从给定的 NodePath .

从给定的 RID .

从给定的 Dictionary .

从给定的 Array .

从给定的 PoolByteArray .

从给定的 PoolIntArray .

从给定的 PoolRealArray .

从给定的 PoolStringArray .

从给定的 PoolVector2Array .

从给定的 PoolVector3Array .

从给定的 PoolColorArray .

返回 true 如果字符串以给定的字符串开头。

返回此字符串的大参数(连续字母对)。

返回字符串的副本,其中包含使用C语言标准转义的特殊字符。

返回字符串的副本,其中转义字符根据C语言标准替换为其含义。

更改某些字母的大小写。将下划线替换为空格,将所有字母转换为小写,然后将空格字符后的第一个字母和每个字母大写。为了 capitalize camelCase mixed_with_underscores ,它会回来的 Capitalize Camelcase Mixed With Underscores .

对另一个字符串执行区分大小写的比较。退换商品 -1 如果小于, +1 如果大于,或 0 如果相等。

返回子字符串的出现次数 what 之间 fromto 位置。如果 fromto 等于0将使用整个字符串。只要 to 等于0,将使用剩余的子字符串。

返回子字符串的出现次数 what (忽略大小写)介于 fromto 位置。如果 fromto 等于0将使用整个字符串。只要 to 等于0,将使用剩余的子字符串。

返回删除了缩进(前导制表符和空格)的字符串副本。

返回 true 如果字符串为空。

返回 true 如果字符串以给定的字符串结尾。

  • void erase ( int position, int chars )

擦除 chars 字符串中从开始的字符 position .

查找子字符串的第一个匹配项。返回子字符串的起始位置,如果找不到,则返回-1。或者,可以传递初始搜索索引。

查找子字符串的最后一个匹配项。返回子字符串的起始位置,如果找不到,则返回-1。

查找子字符串的第一个匹配项,忽略大小写。返回子字符串的起始位置,如果找不到,则返回-1。或者,可以传递初始搜索索引。

通过替换所有出现的 placeholder 具有 values .

如果字符串是有效的文件路径,则返回基本目录名。

如果字符串是有效的文件路径,则返回不带扩展名的完整文件路径。

如果字符串是有效的文件路径,则返回扩展名。

如果字符串是有效的文件路径,则返回文件名。

散列字符串并返回32位整数。

  • int hex_to_int ( )

将包含十六进制数的字符串转换为整数。十六进制字符串的前缀应为“0x”,否则 0 返回。

print("0xff".hex_to_int()) # Print "255"

将字符串转义(编码)为URL友好格式。也称为“URL编码”。

print("https://example.org/?escaped=" + "Godot Engine:'docs'".http_escape())

unescapes(解码)URL编码格式的字符串。也称为“URL解码”。

print("https://example.org/?escaped=" + "Godot%20Engine%3A%27docs%27".http_unescape())

在给定位置插入子字符串。

  • bool is_abs_path ( )

如果字符串是文件或目录的路径,则返回 true 如果路径是绝对的。

  • bool is_rel_path ( )

如果字符串是文件或目录的路径,则返回 true 如果路径是相对的。

返回 true 如果此字符串是给定字符串的子序列。

返回 true 如果此字符串是给定字符串的子序列,则不考虑大小写。

  • bool is_valid_filename ( )

返回 true 如果此字符串没有文件名中不允许的字符,则这些字符为:

: / \ ? * " | % < >

  • bool is_valid_float ( )

返回 true 如果此字符串包含有效的浮点。

  • bool is_valid_hex_number ( bool with_prefix=False )

返回 true 如果此字符串包含有效的十六进制数。如果 with_prefixtrue ,则十六进制数的有效性由 0x 前缀,例如: 0xDEADC0DE .

  • bool is_valid_html_color ( )

返回 true 如果此字符串包含十六进制HTML表示法中的有效颜色。其他HTML标记,如命名颜色或 hsl() 此方法认为颜色无效,将返回 false .

  • bool is_valid_identifier ( )

返回 true 如果此字符串是有效标识符。有效标识符只能包含字母、数字和下划线 (_ )第一个字符不能是数字。

  • bool is_valid_integer ( )

返回 true 如果此字符串包含有效整数。

  • bool is_valid_ip_address ( )

返回 true 如果此字符串包含有效的IP地址。

返回字符串的副本,其中包含使用JSON标准转义的特殊字符。

返回字符串左侧的若干字符。

  • int length ( )

返回字符串的字符数。

返回从左侧删除字符的字符串副本。

简单区分大小写的表达式是否匹配,其中 "*" 匹配零个或多个任意字符和 "?" 匹配除句点之外的任何单个字符 ("."

简单不区分大小写的表达式是否匹配,其中 "*" 匹配零个或多个任意字符和 "?" 匹配除句点之外的任何单个字符 ("."

以字节数组的形式返回字符串的MD5哈希。

以字符串形式返回字符串的MD5哈希。

对另一个字符串执行不区分大小写的比较。退换商品 -1 如果小于, +1 如果大于,或 0 如果相等。

返回位置处的字符代码 at .

将数字格式化为 digits 小数点后。

将数字格式化为 digits 小数点之前。

解码百分比编码字符串。见 percent_encode .

百分比编码字符串。在发送HTTP GET请求(以及urlencoded post请求的主体)时,对URL中的参数进行编码。

如果字符串是路径,则连接 file 在字符串末尾作为子路径。例如。 "this/is".plus_file("path") == "this/is/path" .

用字符串中给定的子字符串替换区分大小写的子字符串。

将不区分大小写的子字符串替换为字符串中给定的子字符串。

对子字符串执行区分大小写的搜索,但从字符串的结尾而不是开头开始。

对子字符串执行不区分大小写的搜索,但从字符串的结尾而不是开头开始。

从给定位置返回字符串的右侧。

将字符串拆分为 delimiter 并返回从右开始的子字符串数组。

返回数组中的拆分按与原始字符串相同的顺序从左到右排序。

如果 maxsplit 它定义了从右到右到右的拆分次数。 maxsplit . 默认值为0表示所有项都被拆分,因此得出的结果与 split .

例如, "One,Two,Three,Four" 将返回 ["Three","Four"] 如果被分割 "," 用一个 maxsplit 值为2。

返回从右侧删除字符的字符串副本。

以字节数组的形式返回字符串的SHA-1哈希。

以字符串形式返回字符串的SHA-1哈希。

以字节数组的形式返回字符串的SHA-256哈希。

以字符串形式返回字符串的SHA-256哈希。

返回文本与此字符串的相似性索引。1表示完全相似,0表示完全不同。

将字符串拆分为 delimiter 并返回子字符串数组。

如果 maxsplit 它定义了从左到右的拆分次数。 maxsplit . 默认值0表示所有项都被拆分。

例如, "One,Two,Three" 将返回 ["One","Two"] 如果被分割 "," 用一个 maxsplit 值为2。

使用分隔符字符串拆分浮点数中的字符串,并返回子字符串数组。

例如, "1,2.5,3" 将返回 [1,2.5,3] 如果被分割 "," .

返回一个字符串的副本,该字符串在开头和结尾处去掉了任何不可打印的字符(包括制表符、空格和换行符)。可选参数用于分别切换左右边缘的剥离。

返回从任何转义符中删除的字符串的副本。这些包括ASCII表(<32)第一页的所有不可打印的控制字符,例如制表 (\t 在c)和换行符中 (\n\r )字符,但不是空格。

从位置返回部分字符串 from 有长度 len . 论点 len 是可选的,使用-1将从给定位置返回剩余字符。

将字符串(字符数组)转换为 PoolByteArray (字节数组)。转换比 to_utf8 ,因为此方法假定字符串中的所有字符都是ASCII字符。

将包含十进制数的字符串转换为 float .

  • int to_int ( )

将包含整数的字符串转换为 int .

返回转换为小写的字符串。

返回转换为大写的字符串。

将字符串(字符数组)转换为 PoolByteArray (字节数组)。转换比 to_ascii ,但支持所有UTF-8字符。因此,您应该更喜欢这个函数而不是 to_ascii .

如果给定字符串以其开头或保持字符串不变,则从开头移除该字符串。

如果给定字符串以其结尾或保持字符串不变,则从结尾移除该字符串。

返回字符串的副本,其中包含使用XML标准转义的特殊字符。

返回字符串的副本,其中转义字符根据XML标准替换为其含义。