class_string.rst 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the String.xml source instead.
  3. .. The source is found in doc/classes or modules/<name>/doc_classes.
  4. .. _class_String:
  5. String
  6. ======
  7. **Category:** Built-In Types
  8. Brief Description
  9. -----------------
  10. Built-in string class.
  11. Methods
  12. -------
  13. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  14. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`bool<class_bool>` from **)** |
  15. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  16. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`int<class_int>` from **)** |
  17. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  18. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`float<class_float>` from **)** |
  19. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  20. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`Vector2<class_Vector2>` from **)** |
  21. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  22. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`Rect2<class_Rect2>` from **)** |
  23. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  24. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`Vector3<class_Vector3>` from **)** |
  25. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`Transform2D<class_Transform2D>` from **)** |
  27. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`Plane<class_Plane>` from **)** |
  29. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`Quat<class_Quat>` from **)** |
  31. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`AABB<class_AABB>` from **)** |
  33. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`Basis<class_Basis>` from **)** |
  35. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`Transform<class_Transform>` from **)** |
  37. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`Color<class_Color>` from **)** |
  39. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`NodePath<class_NodePath>` from **)** |
  41. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`RID<class_RID>` from **)** |
  43. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`Dictionary<class_Dictionary>` from **)** |
  45. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`Array<class_Array>` from **)** |
  47. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`PoolByteArray<class_PoolByteArray>` from **)** |
  49. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`PoolIntArray<class_PoolIntArray>` from **)** |
  51. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`PoolRealArray<class_PoolRealArray>` from **)** |
  53. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`PoolStringArray<class_PoolStringArray>` from **)** |
  55. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` from **)** |
  57. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`PoolVector3Array<class_PoolVector3Array>` from **)** |
  59. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | :ref:`String<class_String>` | :ref:`String<class_String_method_String>` **(** :ref:`PoolColorArray<class_PoolColorArray>` from **)** |
  61. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. | :ref:`bool<class_bool>` | :ref:`begins_with<class_String_method_begins_with>` **(** :ref:`String<class_String>` text **)** |
  63. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`PoolStringArray<class_PoolStringArray>` | :ref:`bigrams<class_String_method_bigrams>` **(** **)** |
  65. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`String<class_String>` | :ref:`c_escape<class_String_method_c_escape>` **(** **)** |
  67. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`String<class_String>` | :ref:`c_unescape<class_String_method_c_unescape>` **(** **)** |
  69. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`String<class_String>` | :ref:`capitalize<class_String_method_capitalize>` **(** **)** |
  71. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`int<class_int>` | :ref:`casecmp_to<class_String_method_casecmp_to>` **(** :ref:`String<class_String>` to **)** |
  73. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`String<class_String>` | :ref:`dedent<class_String_method_dedent>` **(** **)** |
  75. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`bool<class_bool>` | :ref:`empty<class_String_method_empty>` **(** **)** |
  77. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`bool<class_bool>` | :ref:`ends_with<class_String_method_ends_with>` **(** :ref:`String<class_String>` text **)** |
  79. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | void | :ref:`erase<class_String_method_erase>` **(** :ref:`int<class_int>` position, :ref:`int<class_int>` chars **)** |
  81. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`int<class_int>` | :ref:`find<class_String_method_find>` **(** :ref:`String<class_String>` what, :ref:`int<class_int>` from=0 **)** |
  83. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`int<class_int>` | :ref:`find_last<class_String_method_find_last>` **(** :ref:`String<class_String>` what **)** |
  85. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`int<class_int>` | :ref:`findn<class_String_method_findn>` **(** :ref:`String<class_String>` what, :ref:`int<class_int>` from=0 **)** |
  87. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`String<class_String>` | :ref:`format<class_String_method_format>` **(** :ref:`Variant<class_Variant>` values, :ref:`String<class_String>` placeholder={_} **)** |
  89. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`String<class_String>` | :ref:`get_base_dir<class_String_method_get_base_dir>` **(** **)** |
  91. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`String<class_String>` | :ref:`get_basename<class_String_method_get_basename>` **(** **)** |
  93. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`String<class_String>` | :ref:`get_extension<class_String_method_get_extension>` **(** **)** |
  95. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`String<class_String>` | :ref:`get_file<class_String_method_get_file>` **(** **)** |
  97. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`int<class_int>` | :ref:`hash<class_String_method_hash>` **(** **)** |
  99. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`int<class_int>` | :ref:`hex_to_int<class_String_method_hex_to_int>` **(** **)** |
  101. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. | :ref:`String<class_String>` | :ref:`insert<class_String_method_insert>` **(** :ref:`int<class_int>` position, :ref:`String<class_String>` what **)** |
  103. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | :ref:`bool<class_bool>` | :ref:`is_abs_path<class_String_method_is_abs_path>` **(** **)** |
  105. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | :ref:`bool<class_bool>` | :ref:`is_rel_path<class_String_method_is_rel_path>` **(** **)** |
  107. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | :ref:`bool<class_bool>` | :ref:`is_subsequence_of<class_String_method_is_subsequence_of>` **(** :ref:`String<class_String>` text **)** |
  109. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  110. | :ref:`bool<class_bool>` | :ref:`is_subsequence_ofi<class_String_method_is_subsequence_ofi>` **(** :ref:`String<class_String>` text **)** |
  111. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  112. | :ref:`bool<class_bool>` | :ref:`is_valid_filename<class_String_method_is_valid_filename>` **(** **)** |
  113. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  114. | :ref:`bool<class_bool>` | :ref:`is_valid_float<class_String_method_is_valid_float>` **(** **)** |
  115. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  116. | :ref:`bool<class_bool>` | :ref:`is_valid_hex_number<class_String_method_is_valid_hex_number>` **(** :ref:`bool<class_bool>` with_prefix=False **)** |
  117. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  118. | :ref:`bool<class_bool>` | :ref:`is_valid_html_color<class_String_method_is_valid_html_color>` **(** **)** |
  119. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  120. | :ref:`bool<class_bool>` | :ref:`is_valid_identifier<class_String_method_is_valid_identifier>` **(** **)** |
  121. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  122. | :ref:`bool<class_bool>` | :ref:`is_valid_integer<class_String_method_is_valid_integer>` **(** **)** |
  123. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  124. | :ref:`bool<class_bool>` | :ref:`is_valid_ip_address<class_String_method_is_valid_ip_address>` **(** **)** |
  125. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  126. | :ref:`String<class_String>` | :ref:`json_escape<class_String_method_json_escape>` **(** **)** |
  127. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  128. | :ref:`String<class_String>` | :ref:`left<class_String_method_left>` **(** :ref:`int<class_int>` position **)** |
  129. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  130. | :ref:`int<class_int>` | :ref:`length<class_String_method_length>` **(** **)** |
  131. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  132. | :ref:`String<class_String>` | :ref:`lstrip<class_String_method_lstrip>` **(** :ref:`String<class_String>` chars **)** |
  133. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  134. | :ref:`bool<class_bool>` | :ref:`match<class_String_method_match>` **(** :ref:`String<class_String>` expr **)** |
  135. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  136. | :ref:`bool<class_bool>` | :ref:`matchn<class_String_method_matchn>` **(** :ref:`String<class_String>` expr **)** |
  137. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  138. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`md5_buffer<class_String_method_md5_buffer>` **(** **)** |
  139. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  140. | :ref:`String<class_String>` | :ref:`md5_text<class_String_method_md5_text>` **(** **)** |
  141. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  142. | :ref:`int<class_int>` | :ref:`nocasecmp_to<class_String_method_nocasecmp_to>` **(** :ref:`String<class_String>` to **)** |
  143. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  144. | :ref:`int<class_int>` | :ref:`ord_at<class_String_method_ord_at>` **(** :ref:`int<class_int>` at **)** |
  145. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  146. | :ref:`String<class_String>` | :ref:`pad_decimals<class_String_method_pad_decimals>` **(** :ref:`int<class_int>` digits **)** |
  147. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  148. | :ref:`String<class_String>` | :ref:`pad_zeros<class_String_method_pad_zeros>` **(** :ref:`int<class_int>` digits **)** |
  149. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  150. | :ref:`String<class_String>` | :ref:`percent_decode<class_String_method_percent_decode>` **(** **)** |
  151. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  152. | :ref:`String<class_String>` | :ref:`percent_encode<class_String_method_percent_encode>` **(** **)** |
  153. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  154. | :ref:`String<class_String>` | :ref:`plus_file<class_String_method_plus_file>` **(** :ref:`String<class_String>` file **)** |
  155. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  156. | :ref:`String<class_String>` | :ref:`replace<class_String_method_replace>` **(** :ref:`String<class_String>` what, :ref:`String<class_String>` forwhat **)** |
  157. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  158. | :ref:`String<class_String>` | :ref:`replacen<class_String_method_replacen>` **(** :ref:`String<class_String>` what, :ref:`String<class_String>` forwhat **)** |
  159. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  160. | :ref:`int<class_int>` | :ref:`rfind<class_String_method_rfind>` **(** :ref:`String<class_String>` what, :ref:`int<class_int>` from=-1 **)** |
  161. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  162. | :ref:`int<class_int>` | :ref:`rfindn<class_String_method_rfindn>` **(** :ref:`String<class_String>` what, :ref:`int<class_int>` from=-1 **)** |
  163. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  164. | :ref:`String<class_String>` | :ref:`right<class_String_method_right>` **(** :ref:`int<class_int>` position **)** |
  165. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  166. | :ref:`PoolStringArray<class_PoolStringArray>` | :ref:`rsplit<class_String_method_rsplit>` **(** :ref:`String<class_String>` divisor, :ref:`bool<class_bool>` allow_empty=True, :ref:`int<class_int>` maxsplit=0 **)** |
  167. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  168. | :ref:`String<class_String>` | :ref:`rstrip<class_String_method_rstrip>` **(** :ref:`String<class_String>` chars **)** |
  169. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  170. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`sha256_buffer<class_String_method_sha256_buffer>` **(** **)** |
  171. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  172. | :ref:`String<class_String>` | :ref:`sha256_text<class_String_method_sha256_text>` **(** **)** |
  173. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  174. | :ref:`float<class_float>` | :ref:`similarity<class_String_method_similarity>` **(** :ref:`String<class_String>` text **)** |
  175. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  176. | :ref:`PoolStringArray<class_PoolStringArray>` | :ref:`split<class_String_method_split>` **(** :ref:`String<class_String>` divisor, :ref:`bool<class_bool>` allow_empty=True, :ref:`int<class_int>` maxsplit=0 **)** |
  177. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  178. | :ref:`PoolRealArray<class_PoolRealArray>` | :ref:`split_floats<class_String_method_split_floats>` **(** :ref:`String<class_String>` divisor, :ref:`bool<class_bool>` allow_empty=True **)** |
  179. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  180. | :ref:`String<class_String>` | :ref:`strip_edges<class_String_method_strip_edges>` **(** :ref:`bool<class_bool>` left=True, :ref:`bool<class_bool>` right=True **)** |
  181. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  182. | :ref:`String<class_String>` | :ref:`substr<class_String_method_substr>` **(** :ref:`int<class_int>` from, :ref:`int<class_int>` len **)** |
  183. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  184. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`to_ascii<class_String_method_to_ascii>` **(** **)** |
  185. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  186. | :ref:`float<class_float>` | :ref:`to_float<class_String_method_to_float>` **(** **)** |
  187. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  188. | :ref:`int<class_int>` | :ref:`to_int<class_String_method_to_int>` **(** **)** |
  189. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  190. | :ref:`String<class_String>` | :ref:`to_lower<class_String_method_to_lower>` **(** **)** |
  191. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  192. | :ref:`String<class_String>` | :ref:`to_upper<class_String_method_to_upper>` **(** **)** |
  193. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  194. | :ref:`PoolByteArray<class_PoolByteArray>` | :ref:`to_utf8<class_String_method_to_utf8>` **(** **)** |
  195. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  196. | :ref:`String<class_String>` | :ref:`trim_prefix<class_String_method_trim_prefix>` **(** :ref:`String<class_String>` prefix **)** |
  197. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  198. | :ref:`String<class_String>` | :ref:`trim_suffix<class_String_method_trim_suffix>` **(** :ref:`String<class_String>` suffix **)** |
  199. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  200. | :ref:`String<class_String>` | :ref:`xml_escape<class_String_method_xml_escape>` **(** **)** |
  201. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  202. | :ref:`String<class_String>` | :ref:`xml_unescape<class_String_method_xml_unescape>` **(** **)** |
  203. +-----------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  204. Description
  205. -----------
  206. This is the built-in string class (and the one used by GDScript). It supports Unicode and provides all necessary means for string handling. Strings are reference counted and use a copy-on-write approach, so passing them around is cheap in resources.
  207. Tutorials
  208. ---------
  209. - :doc:`../getting_started/scripting/gdscript/gdscript_format_string`
  210. Method Descriptions
  211. -------------------
  212. .. _class_String_method_String:
  213. - :ref:`String<class_String>` **String** **(** :ref:`bool<class_bool>` from **)**
  214. Constructs a new String from the given :ref:`bool<class_bool>`.
  215. - :ref:`String<class_String>` **String** **(** :ref:`int<class_int>` from **)**
  216. Constructs a new String from the given :ref:`int<class_int>`.
  217. - :ref:`String<class_String>` **String** **(** :ref:`float<class_float>` from **)**
  218. Constructs a new String from the given :ref:`float<class_float>`.
  219. - :ref:`String<class_String>` **String** **(** :ref:`Vector2<class_Vector2>` from **)**
  220. Constructs a new String from the given :ref:`Vector2<class_Vector2>`.
  221. - :ref:`String<class_String>` **String** **(** :ref:`Rect2<class_Rect2>` from **)**
  222. Constructs a new String from the given :ref:`Rect2<class_Rect2>`.
  223. - :ref:`String<class_String>` **String** **(** :ref:`Vector3<class_Vector3>` from **)**
  224. Constructs a new String from the given :ref:`Vector3<class_Vector3>`.
  225. - :ref:`String<class_String>` **String** **(** :ref:`Transform2D<class_Transform2D>` from **)**
  226. Constructs a new String from the given :ref:`Transform2D<class_Transform2D>`.
  227. - :ref:`String<class_String>` **String** **(** :ref:`Plane<class_Plane>` from **)**
  228. Constructs a new String from the given :ref:`Plane<class_Plane>`.
  229. - :ref:`String<class_String>` **String** **(** :ref:`Quat<class_Quat>` from **)**
  230. Constructs a new String from the given :ref:`Quat<class_Quat>`.
  231. - :ref:`String<class_String>` **String** **(** :ref:`AABB<class_AABB>` from **)**
  232. Constructs a new String from the given :ref:`AABB<class_AABB>`.
  233. - :ref:`String<class_String>` **String** **(** :ref:`Basis<class_Basis>` from **)**
  234. Constructs a new String from the given :ref:`Basis<class_Basis>`.
  235. - :ref:`String<class_String>` **String** **(** :ref:`Transform<class_Transform>` from **)**
  236. Constructs a new String from the given :ref:`Transform<class_Transform>`.
  237. - :ref:`String<class_String>` **String** **(** :ref:`Color<class_Color>` from **)**
  238. Constructs a new String from the given :ref:`Color<class_Color>`.
  239. - :ref:`String<class_String>` **String** **(** :ref:`NodePath<class_NodePath>` from **)**
  240. Constructs a new String from the given :ref:`NodePath<class_NodePath>`.
  241. - :ref:`String<class_String>` **String** **(** :ref:`RID<class_RID>` from **)**
  242. Constructs a new String from the given :ref:`RID<class_RID>`.
  243. - :ref:`String<class_String>` **String** **(** :ref:`Dictionary<class_Dictionary>` from **)**
  244. Constructs a new String from the given :ref:`Dictionary<class_Dictionary>`.
  245. - :ref:`String<class_String>` **String** **(** :ref:`Array<class_Array>` from **)**
  246. Constructs a new String from the given :ref:`Array<class_Array>`.
  247. - :ref:`String<class_String>` **String** **(** :ref:`PoolByteArray<class_PoolByteArray>` from **)**
  248. Constructs a new String from the given :ref:`PoolByteArray<class_PoolByteArray>`.
  249. - :ref:`String<class_String>` **String** **(** :ref:`PoolIntArray<class_PoolIntArray>` from **)**
  250. Constructs a new String from the given :ref:`PoolIntArray<class_PoolIntArray>`.
  251. - :ref:`String<class_String>` **String** **(** :ref:`PoolRealArray<class_PoolRealArray>` from **)**
  252. Constructs a new String from the given :ref:`PoolRealArray<class_PoolRealArray>`.
  253. - :ref:`String<class_String>` **String** **(** :ref:`PoolStringArray<class_PoolStringArray>` from **)**
  254. Constructs a new String from the given :ref:`PoolStringArray<class_PoolStringArray>`.
  255. - :ref:`String<class_String>` **String** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` from **)**
  256. Constructs a new String from the given :ref:`PoolVector2Array<class_PoolVector2Array>`.
  257. - :ref:`String<class_String>` **String** **(** :ref:`PoolVector3Array<class_PoolVector3Array>` from **)**
  258. Constructs a new String from the given :ref:`PoolVector3Array<class_PoolVector3Array>`.
  259. - :ref:`String<class_String>` **String** **(** :ref:`PoolColorArray<class_PoolColorArray>` from **)**
  260. Constructs a new String from the given :ref:`PoolColorArray<class_PoolColorArray>`.
  261. .. _class_String_method_begins_with:
  262. - :ref:`bool<class_bool>` **begins_with** **(** :ref:`String<class_String>` text **)**
  263. Returns ``true`` if the string begins with the given string.
  264. .. _class_String_method_bigrams:
  265. - :ref:`PoolStringArray<class_PoolStringArray>` **bigrams** **(** **)**
  266. Returns the bigrams (pairs of consecutive letters) of this string.
  267. .. _class_String_method_c_escape:
  268. - :ref:`String<class_String>` **c_escape** **(** **)**
  269. Returns a copy of the string with special characters escaped using the C language standard.
  270. .. _class_String_method_c_unescape:
  271. - :ref:`String<class_String>` **c_unescape** **(** **)**
  272. Returns a copy of the string with escaped characters replaced by their meanings according to the C language standard.
  273. .. _class_String_method_capitalize:
  274. - :ref:`String<class_String>` **capitalize** **(** **)**
  275. Changes the case of some letters. Replaces underscores with spaces, converts all letters to lowercase, then capitalizes first and every letter following the space character. For ``capitalize camelCase mixed_with_underscores`` it will return ``Capitalize Camelcase Mixed With Underscores``.
  276. .. _class_String_method_casecmp_to:
  277. - :ref:`int<class_int>` **casecmp_to** **(** :ref:`String<class_String>` to **)**
  278. Performs a case-sensitive comparison to another string. Returns ``-1`` if less than, ``+1`` if greater than, or ``0`` if equal.
  279. .. _class_String_method_dedent:
  280. - :ref:`String<class_String>` **dedent** **(** **)**
  281. Removes indentation from string.
  282. .. _class_String_method_empty:
  283. - :ref:`bool<class_bool>` **empty** **(** **)**
  284. Returns ``true`` if the string is empty.
  285. .. _class_String_method_ends_with:
  286. - :ref:`bool<class_bool>` **ends_with** **(** :ref:`String<class_String>` text **)**
  287. Returns ``true`` if the string ends with the given string.
  288. .. _class_String_method_erase:
  289. - void **erase** **(** :ref:`int<class_int>` position, :ref:`int<class_int>` chars **)**
  290. Erases ``chars`` characters from the string starting from ``position``.
  291. .. _class_String_method_find:
  292. - :ref:`int<class_int>` **find** **(** :ref:`String<class_String>` what, :ref:`int<class_int>` from=0 **)**
  293. Finds the first occurrence of a substring. Returns the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed.
  294. .. _class_String_method_find_last:
  295. - :ref:`int<class_int>` **find_last** **(** :ref:`String<class_String>` what **)**
  296. Finds the last occurrence of a substring. Returns the starting position of the substring or -1 if not found.
  297. .. _class_String_method_findn:
  298. - :ref:`int<class_int>` **findn** **(** :ref:`String<class_String>` what, :ref:`int<class_int>` from=0 **)**
  299. Finds the first occurrence of a substring, ignoring case. Returns the starting position of the substring or -1 if not found. Optionally, the initial search index can be passed.
  300. .. _class_String_method_format:
  301. - :ref:`String<class_String>` **format** **(** :ref:`Variant<class_Variant>` values, :ref:`String<class_String>` placeholder={_} **)**
  302. Formats the string by replacing all occurrences of ``placeholder`` with ``values``.
  303. .. _class_String_method_get_base_dir:
  304. - :ref:`String<class_String>` **get_base_dir** **(** **)**
  305. If the string is a valid file path, returns the base directory name.
  306. .. _class_String_method_get_basename:
  307. - :ref:`String<class_String>` **get_basename** **(** **)**
  308. If the string is a valid file path, returns the full file path without the extension.
  309. .. _class_String_method_get_extension:
  310. - :ref:`String<class_String>` **get_extension** **(** **)**
  311. If the string is a valid file path, returns the extension.
  312. .. _class_String_method_get_file:
  313. - :ref:`String<class_String>` **get_file** **(** **)**
  314. If the string is a valid file path, returns the filename.
  315. .. _class_String_method_hash:
  316. - :ref:`int<class_int>` **hash** **(** **)**
  317. Hashes the string and returns a 32-bit integer.
  318. .. _class_String_method_hex_to_int:
  319. - :ref:`int<class_int>` **hex_to_int** **(** **)**
  320. Converts a string containing a hexadecimal number into an integer.
  321. .. _class_String_method_insert:
  322. - :ref:`String<class_String>` **insert** **(** :ref:`int<class_int>` position, :ref:`String<class_String>` what **)**
  323. Inserts a substring at a given position.
  324. .. _class_String_method_is_abs_path:
  325. - :ref:`bool<class_bool>` **is_abs_path** **(** **)**
  326. If the string is a path to a file or directory, returns ``true`` if the path is absolute.
  327. .. _class_String_method_is_rel_path:
  328. - :ref:`bool<class_bool>` **is_rel_path** **(** **)**
  329. If the string is a path to a file or directory, returns ``true`` if the path is relative.
  330. .. _class_String_method_is_subsequence_of:
  331. - :ref:`bool<class_bool>` **is_subsequence_of** **(** :ref:`String<class_String>` text **)**
  332. Returns ``true`` if this string is a subsequence of the given string.
  333. .. _class_String_method_is_subsequence_ofi:
  334. - :ref:`bool<class_bool>` **is_subsequence_ofi** **(** :ref:`String<class_String>` text **)**
  335. Returns ``true`` if this string is a subsequence of the given string, without considering case.
  336. .. _class_String_method_is_valid_filename:
  337. - :ref:`bool<class_bool>` **is_valid_filename** **(** **)**
  338. Returns ``true`` if this string is free from characters that aren't allowed in file names, those being:
  339. ``: / \ ? * " | % < >``
  340. .. _class_String_method_is_valid_float:
  341. - :ref:`bool<class_bool>` **is_valid_float** **(** **)**
  342. Returns ``true`` if this string contains a valid float.
  343. .. _class_String_method_is_valid_hex_number:
  344. - :ref:`bool<class_bool>` **is_valid_hex_number** **(** :ref:`bool<class_bool>` with_prefix=False **)**
  345. Returns ``true`` if this string contains a valid hexadecimal number. If ``with_prefix`` is ``true``, then a validity of the hexadecimal number is determined by ``0x`` prefix, for instance: ``0xDEADC0DE``.
  346. .. _class_String_method_is_valid_html_color:
  347. - :ref:`bool<class_bool>` **is_valid_html_color** **(** **)**
  348. Returns ``true`` if this string contains a valid color in HTML notation.
  349. .. _class_String_method_is_valid_identifier:
  350. - :ref:`bool<class_bool>` **is_valid_identifier** **(** **)**
  351. Returns ``true`` if this string is a valid identifier. A valid identifier may contain only letters, digits and underscores (``_``) and the first character may not be a digit.
  352. .. _class_String_method_is_valid_integer:
  353. - :ref:`bool<class_bool>` **is_valid_integer** **(** **)**
  354. Returns ``true`` if this string contains a valid integer.
  355. .. _class_String_method_is_valid_ip_address:
  356. - :ref:`bool<class_bool>` **is_valid_ip_address** **(** **)**
  357. Returns ``true`` if this string contains a valid IP address.
  358. .. _class_String_method_json_escape:
  359. - :ref:`String<class_String>` **json_escape** **(** **)**
  360. Returns a copy of the string with special characters escaped using the JSON standard.
  361. .. _class_String_method_left:
  362. - :ref:`String<class_String>` **left** **(** :ref:`int<class_int>` position **)**
  363. Returns a number of characters from the left of the string.
  364. .. _class_String_method_length:
  365. - :ref:`int<class_int>` **length** **(** **)**
  366. Returns the string's amount of characters.
  367. .. _class_String_method_lstrip:
  368. - :ref:`String<class_String>` **lstrip** **(** :ref:`String<class_String>` chars **)**
  369. Returns a copy of the string with characters removed from the left.
  370. .. _class_String_method_match:
  371. - :ref:`bool<class_bool>` **match** **(** :ref:`String<class_String>` expr **)**
  372. Does a simple expression match, where ``*`` matches zero or more arbitrary characters and ``?`` matches any single character except '.'.
  373. .. _class_String_method_matchn:
  374. - :ref:`bool<class_bool>` **matchn** **(** :ref:`String<class_String>` expr **)**
  375. Does a simple case insensitive expression match, using ``?`` and ``*`` wildcards (see :ref:`match<class_String_method_match>`).
  376. .. _class_String_method_md5_buffer:
  377. - :ref:`PoolByteArray<class_PoolByteArray>` **md5_buffer** **(** **)**
  378. Returns the MD5 hash of the string as an array of bytes.
  379. .. _class_String_method_md5_text:
  380. - :ref:`String<class_String>` **md5_text** **(** **)**
  381. Returns the MD5 hash of the string as a string.
  382. .. _class_String_method_nocasecmp_to:
  383. - :ref:`int<class_int>` **nocasecmp_to** **(** :ref:`String<class_String>` to **)**
  384. Performs a case-insensitive comparison to another string. Returns ``-1`` if less than, ``+1`` if greater than, or ``0`` if equal.
  385. .. _class_String_method_ord_at:
  386. - :ref:`int<class_int>` **ord_at** **(** :ref:`int<class_int>` at **)**
  387. Returns the character code at position ``at``.
  388. .. _class_String_method_pad_decimals:
  389. - :ref:`String<class_String>` **pad_decimals** **(** :ref:`int<class_int>` digits **)**
  390. Formats a number to have an exact number of ``digits`` after the decimal point.
  391. .. _class_String_method_pad_zeros:
  392. - :ref:`String<class_String>` **pad_zeros** **(** :ref:`int<class_int>` digits **)**
  393. Formats a number to have an exact number of ``digits`` before the decimal point.
  394. .. _class_String_method_percent_decode:
  395. - :ref:`String<class_String>` **percent_decode** **(** **)**
  396. Decode a percent-encoded string. See :ref:`percent_encode<class_String_method_percent_encode>`.
  397. .. _class_String_method_percent_encode:
  398. - :ref:`String<class_String>` **percent_encode** **(** **)**
  399. Percent-encodes a string. Encodes parameters in a URL when sending a HTTP GET request (and bodies of form-urlencoded POST requests).
  400. .. _class_String_method_plus_file:
  401. - :ref:`String<class_String>` **plus_file** **(** :ref:`String<class_String>` file **)**
  402. If the string is a path, this concatenates ``file`` at the end of the string as a subpath. E.g. ``"this/is".plus_file("path") == "this/is/path"``.
  403. .. _class_String_method_replace:
  404. - :ref:`String<class_String>` **replace** **(** :ref:`String<class_String>` what, :ref:`String<class_String>` forwhat **)**
  405. Replaces occurrences of a substring with the given one inside the string.
  406. .. _class_String_method_replacen:
  407. - :ref:`String<class_String>` **replacen** **(** :ref:`String<class_String>` what, :ref:`String<class_String>` forwhat **)**
  408. Replaces occurrences of a substring with the given one inside the string. Ignores case.
  409. .. _class_String_method_rfind:
  410. - :ref:`int<class_int>` **rfind** **(** :ref:`String<class_String>` what, :ref:`int<class_int>` from=-1 **)**
  411. Performs a search for a substring, but starts from the end of the string instead of the beginning.
  412. .. _class_String_method_rfindn:
  413. - :ref:`int<class_int>` **rfindn** **(** :ref:`String<class_String>` what, :ref:`int<class_int>` from=-1 **)**
  414. Performs a search for a substring, but starts from the end of the string instead of the beginning. Ignores case.
  415. .. _class_String_method_right:
  416. - :ref:`String<class_String>` **right** **(** :ref:`int<class_int>` position **)**
  417. Returns the right side of the string from a given position.
  418. .. _class_String_method_rsplit:
  419. - :ref:`PoolStringArray<class_PoolStringArray>` **rsplit** **(** :ref:`String<class_String>` divisor, :ref:`bool<class_bool>` allow_empty=True, :ref:`int<class_int>` maxsplit=0 **)**
  420. Splits the string by a ``divisor`` string and returns an array of the substrings, starting from right.
  421. **Example:** ``"One,Two,Three"`` will return ``["One","Two","Three"]`` if split by ``","``.
  422. If ``maxsplit`` is specified, then it is number of splits to do, default is 0 which splits all the items.
  423. .. _class_String_method_rstrip:
  424. - :ref:`String<class_String>` **rstrip** **(** :ref:`String<class_String>` chars **)**
  425. Returns a copy of the string with characters removed from the right.
  426. .. _class_String_method_sha256_buffer:
  427. - :ref:`PoolByteArray<class_PoolByteArray>` **sha256_buffer** **(** **)**
  428. Returns the SHA-256 hash of the string as an array of bytes.
  429. .. _class_String_method_sha256_text:
  430. - :ref:`String<class_String>` **sha256_text** **(** **)**
  431. Returns the SHA-256 hash of the string as a string.
  432. .. _class_String_method_similarity:
  433. - :ref:`float<class_float>` **similarity** **(** :ref:`String<class_String>` text **)**
  434. Returns the similarity index of the text compared to this string. 1 means totally similar and 0 means totally dissimilar.
  435. .. _class_String_method_split:
  436. - :ref:`PoolStringArray<class_PoolStringArray>` **split** **(** :ref:`String<class_String>` divisor, :ref:`bool<class_bool>` allow_empty=True, :ref:`int<class_int>` maxsplit=0 **)**
  437. Splits the string by a divisor string and returns an array of the substrings.
  438. **Example:** ``"One,Two,Three"`` will return ``["One","Two","Three"]`` if split by ``","``.
  439. If ``maxsplit`` is given, at most maxsplit number of splits occur, and the remainder of the string is returned as the final element of the list (thus, the list will have at most maxsplit+1 elements)
  440. .. _class_String_method_split_floats:
  441. - :ref:`PoolRealArray<class_PoolRealArray>` **split_floats** **(** :ref:`String<class_String>` divisor, :ref:`bool<class_bool>` allow_empty=True **)**
  442. Splits the string in floats by using a divisor string and returns an array of the substrings.
  443. **Example:** ``"1,2.5,3"`` will return ``[1,2.5,3]`` if split by ``","``.
  444. .. _class_String_method_strip_edges:
  445. - :ref:`String<class_String>` **strip_edges** **(** :ref:`bool<class_bool>` left=True, :ref:`bool<class_bool>` right=True **)**
  446. Returns a copy of the string stripped of any non-printable character at the beginning and the end. The optional arguments are used to toggle stripping on the left and right edges respectively.
  447. .. _class_String_method_substr:
  448. - :ref:`String<class_String>` **substr** **(** :ref:`int<class_int>` from, :ref:`int<class_int>` len **)**
  449. Returns part of the string from the position ``from`` with length ``len``.
  450. .. _class_String_method_to_ascii:
  451. - :ref:`PoolByteArray<class_PoolByteArray>` **to_ascii** **(** **)**
  452. Converts the String (which is a character array) to :ref:`PoolByteArray<class_PoolByteArray>` (which is an array of bytes). The conversion is sped up in comparison to :ref:`to_utf8<class_String_method_to_utf8>` with the assumption that all the characters the String contains are only ASCII characters.
  453. .. _class_String_method_to_float:
  454. - :ref:`float<class_float>` **to_float** **(** **)**
  455. Converts a string containing a decimal number into a ``float``.
  456. .. _class_String_method_to_int:
  457. - :ref:`int<class_int>` **to_int** **(** **)**
  458. Converts a string containing an integer number into an ``int``.
  459. .. _class_String_method_to_lower:
  460. - :ref:`String<class_String>` **to_lower** **(** **)**
  461. Returns the string converted to lowercase.
  462. .. _class_String_method_to_upper:
  463. - :ref:`String<class_String>` **to_upper** **(** **)**
  464. Returns the string converted to uppercase.
  465. .. _class_String_method_to_utf8:
  466. - :ref:`PoolByteArray<class_PoolByteArray>` **to_utf8** **(** **)**
  467. Converts the String (which is an array of characters) to :ref:`PoolByteArray<class_PoolByteArray>` (which is an array of bytes). The conversion is a bit slower than :ref:`to_ascii<class_String_method_to_ascii>`, but supports all UTF-8 characters. Therefore, you should prefer this function over :ref:`to_ascii<class_String_method_to_ascii>`.
  468. .. _class_String_method_trim_prefix:
  469. - :ref:`String<class_String>` **trim_prefix** **(** :ref:`String<class_String>` prefix **)**
  470. Removes a given string from the start if it starts with it or leaves the string unchanged.
  471. .. _class_String_method_trim_suffix:
  472. - :ref:`String<class_String>` **trim_suffix** **(** :ref:`String<class_String>` suffix **)**
  473. Removes a given string from the end if it ends with it or leaves the string unchanged.
  474. .. _class_String_method_xml_escape:
  475. - :ref:`String<class_String>` **xml_escape** **(** **)**
  476. Returns a copy of the string with special characters escaped using the XML standard.
  477. .. _class_String_method_xml_unescape:
  478. - :ref:`String<class_String>` **xml_unescape** **(** **)**
  479. Returns a copy of the string with escaped characters replaced by their meanings according to the XML standard.