summaryrefslogtreecommitdiff
path: root/doc/classes/String.xml
diff options
context:
space:
mode:
Diffstat (limited to 'doc/classes/String.xml')
-rw-r--r--doc/classes/String.xml107
1 files changed, 85 insertions, 22 deletions
diff --git a/doc/classes/String.xml b/doc/classes/String.xml
index c1a7a2edda..9f197dae02 100644
--- a/doc/classes/String.xml
+++ b/doc/classes/String.xml
@@ -49,7 +49,10 @@
<method name="bigrams" qualifiers="const">
<return type="PackedStringArray" />
<description>
- Returns the bigrams (pairs of consecutive letters) of this string.
+ Returns an array containing the bigrams (pairs of consecutive letters) of this string.
+ [codeblock]
+ print("Bigrams".bigrams()) # Prints "[Bi, ig, gr, ra, am, ms]"
+ [/codeblock]
</description>
</method>
<method name="bin_to_int" qualifiers="const">
@@ -101,6 +104,11 @@
<return type="String" />
<argument index="0" name="char" type="int" />
<description>
+ Directly converts an decimal integer to a unicode character. Tables of these characters can be found in various locations, for example [url=https://unicodelookup.com/]here.[/url]
+ [codeblock]
+ print(String.chr(65)) # Prints "A"
+ print(String.chr(129302)) # Prints "🤖" (robot face emoji)
+ [/codeblock]
</description>
</method>
<method name="contains" qualifiers="const">
@@ -172,7 +180,22 @@
<argument index="0" name="values" type="Variant" />
<argument index="1" name="placeholder" type="String" default="&quot;{_}&quot;" />
<description>
- Formats the string by replacing all occurrences of [code]placeholder[/code] with [code]values[/code].
+ Formats the string by replacing all occurrences of [code]placeholder[/code] with the elements of [code]values[/code].
+ [code]values[/code] can be a [Dictionary] or an [Array]. Any underscores in [code]placeholder[/code] will be replaced with the corresponding keys in advance. Array elements use their index as keys.
+ [codeblock]
+ # Prints: Waiting for Godot is a play by Samuel Beckett, and Godot Engine is named after it.
+ var use_array_values = "Waiting for {0} is a play by {1}, and {0} Engine is named after it."
+ print(use_array_values.format(["Godot", "Samuel Beckett"]))
+
+ # Prints: User 42 is Godot.
+ print("User {id} is {name}.".format({"id": 42, "name": "Godot"}))
+ [/codeblock]
+ Some additional handling is performed when [code]values[/code] is an array. If [code]placeholder[/code] does not contain an underscore, the elements of the array will be used to replace one occurrence of the placeholder in turn; If an array element is another 2-element array, it'll be interpreted as a key-value pair.
+ [codeblock]
+ # Prints: User 42 is Godot.
+ print("User {} is {}.".format([42, "Godot"], "{}"))
+ print("User {id} is {name}.".format([["id", 42], ["name", "Godot"]]))
+ [/codeblock]
</description>
</method>
<method name="get_base_dir" qualifiers="const">
@@ -265,6 +288,8 @@
<return type="String" />
<argument index="0" name="size" type="int" />
<description>
+ Converts an integer representing a number of bytes into a human-readable form.
+ Note that this output is in [url=https://en.wikipedia.org/wiki/Binary_prefix#IEC_prefixes]IEC prefix format[/url], and includes [code]B[/code], [code]KiB[/code], [code]MiB[/code], [code]GiB[/code], [code]TiB[/code], [code]PiB[/code], and [code]EiB[/code].
</description>
</method>
<method name="indent" qualifiers="const">
@@ -326,7 +351,13 @@
<method name="is_valid_float" qualifiers="const">
<return type="bool" />
<description>
- Returns [code]true[/code] if this string contains a valid float.
+ Returns [code]true[/code] if this string contains a valid float. This is inclusive of integers, and also supports exponents:
+ [codeblock]
+ print("1.7".is_valid_float()) # Prints "true"
+ print("24".is_valid_float()) # Prints "true"
+ print("7e3".is_valid_float()) # Prints "true"
+ print("Hello".is_valid_float()) # Prints "false"
+ [/codeblock]
</description>
</method>
<method name="is_valid_hex_number" qualifiers="const">
@@ -346,12 +377,24 @@
<return type="bool" />
<description>
Returns [code]true[/code] if this string is a valid identifier. A valid identifier may contain only letters, digits and underscores ([code]_[/code]) and the first character may not be a digit.
+ [codeblock]
+ print("good_ident_1".is_valid_identifier()) # Prints "true"
+ print("1st_bad_ident".is_valid_identifier()) # Prints "false"
+ print("bad_ident_#2".is_valid_identifier()) # Prints "false"
+ [/codeblock]
</description>
</method>
<method name="is_valid_int" qualifiers="const">
<return type="bool" />
<description>
Returns [code]true[/code] if this string contains a valid integer.
+ [codeblock]
+ print("7".is_valid_int()) # Prints "true"
+ print("14.6".is_valid_int()) # Prints "false"
+ print("L".is_valid_int()) # Prints "false"
+ print("+3".is_valid_int()) # Prints "true"
+ print("-12".is_valid_int()) # Prints "true"
+ [/codeblock]
</description>
</method>
<method name="is_valid_ip_address" qualifiers="const">
@@ -384,9 +427,9 @@
</method>
<method name="left" qualifiers="const">
<return type="String" />
- <argument index="0" name="position" type="int" />
+ <argument index="0" name="length" type="int" />
<description>
- Returns a number of characters from the left of the string. If negative [code]position[/code] is used, the characters are counted downwards from [String]'s length.
+ Returns a number of characters from the left of the string. If negative [code]length[/code] is used, the characters are counted downwards from [String]'s length.
Examples:
[codeblock]
print("sample text".left(3)) #prints "sam"
@@ -420,14 +463,14 @@
<return type="bool" />
<argument index="0" name="expr" type="String" />
<description>
- Does a simple case-sensitive expression match, where [code]"*"[/code] matches zero or more arbitrary characters and [code]"?"[/code] matches any single character except a period ([code]"."[/code]).
+ Does a simple case-sensitive expression match, where [code]"*"[/code] matches zero or more arbitrary characters and [code]"?"[/code] matches any single character except a period ([code]"."[/code]). An empty string or empty expression always evaluates to [code]false[/code].
</description>
</method>
<method name="matchn" qualifiers="const">
<return type="bool" />
<argument index="0" name="expr" type="String" />
<description>
- Does a simple case-insensitive expression match, where [code]"*"[/code] matches zero or more arbitrary characters and [code]"?"[/code] matches any single character except a period ([code]"."[/code]).
+ Does a simple case-insensitive expression match, where [code]"*"[/code] matches zero or more arbitrary characters and [code]"?"[/code] matches any single character except a period ([code]"."[/code]). An empty string or empty expression always evaluates to [code]false[/code].
</description>
</method>
<method name="md5_buffer" qualifiers="const">
@@ -485,12 +528,30 @@
[/codeblock]
</description>
</method>
+ <method name="num_int64" qualifiers="static">
+ <return type="String" />
+ <argument index="0" name="number" type="int" />
+ <argument index="1" name="base" type="int" default="10" />
+ <argument index="2" name="capitalize_hex" type="bool" default="false" />
+ <description>
+ Converts a signed [int] to a string representation of a number.
+ </description>
+ </method>
<method name="num_scientific" qualifiers="static">
<return type="String" />
<argument index="0" name="number" type="float" />
<description>
</description>
</method>
+ <method name="num_uint64" qualifiers="static">
+ <return type="String" />
+ <argument index="0" name="number" type="int" />
+ <argument index="1" name="base" type="int" default="10" />
+ <argument index="2" name="capitalize_hex" type="bool" default="false" />
+ <description>
+ Converts a unsigned [int] to a string representation of a number.
+ </description>
+ </method>
<method name="pad_decimals" qualifiers="const">
<return type="String" />
<argument index="0" name="digits" type="int" />
@@ -553,9 +614,9 @@
</method>
<method name="right" qualifiers="const">
<return type="String" />
- <argument index="0" name="position" type="int" />
+ <argument index="0" name="length" type="int" />
<description>
- Returns a number of characters from the right of the string. If negative [code]position[/code] is used, the characters are counted downwards from [String]'s length.
+ Returns a number of characters from the right of the string. If negative [code]length[/code] is used, the characters are counted downwards from [String]'s length.
Examples:
[codeblock]
print("sample text".right(3)) #prints "ext"
@@ -586,8 +647,8 @@
var some_string = "One,Two,Three,Four"
var some_array = some_string.rsplit(",", true, 1)
print(some_array.size()) # Prints 2
- print(some_array[0]) # Prints "Four"
- print(some_array[1]) # Prints "Three,Two,One"
+ print(some_array[0]) # Prints "One,Two,Three"
+ print(some_array[1]) # Prints "Four"
[/gdscript]
[csharp]
// There is no Rsplit.
@@ -631,7 +692,13 @@
<return type="float" />
<argument index="0" name="text" type="String" />
<description>
- Returns the similarity index of the text compared to this string. 1 means totally similar and 0 means totally dissimilar.
+ Returns the similarity index ([url=https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient]Sorensen-Dice coefficient[/url]) of this string compared to another. A result of 1.0 means totally similar, while 0.0 means totally dissimilar.
+ [codeblock]
+ print("ABC123".similarity("ABC123")) # Prints "1"
+ print("ABC123".similarity("XYZ456")) # Prints "0"
+ print("ABC123".similarity("123ABC")) # Prints "0.8"
+ print("ABC123".similarity("abc123")) # Prints "0.4"
+ [/codeblock]
</description>
</method>
<method name="simplify_path" qualifiers="const">
@@ -830,11 +897,6 @@
<operators>
<operator name="operator !=">
<return type="bool" />
- <description>
- </description>
- </operator>
- <operator name="operator !=">
- <return type="bool" />
<argument index="0" name="right" type="String" />
<description>
</description>
@@ -857,20 +919,21 @@
<description>
</description>
</operator>
- <operator name="operator &lt;">
- <return type="bool" />
- <argument index="0" name="right" type="String" />
+ <operator name="operator +">
+ <return type="String" />
+ <argument index="0" name="right" type="int" />
<description>
</description>
</operator>
- <operator name="operator &lt;=">
+ <operator name="operator &lt;">
<return type="bool" />
<argument index="0" name="right" type="String" />
<description>
</description>
</operator>
- <operator name="operator ==">
+ <operator name="operator &lt;=">
<return type="bool" />
+ <argument index="0" name="right" type="String" />
<description>
</description>
</operator>