Skip to content

Commit f0852b8

Browse files
committed
Make explicit that string comparison is by default case sensitive
1 parent 0c51ede commit f0852b8

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

doc/classes/String.xml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
</brief_description>
66
<description>
77
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.
8-
Some string methods have corresponding variations. Variations suffixed with [code]n[/code] ([method countn], [method findn], [method replacen], etc.) are [b]case-insensitive[/b] (they make no distinction between uppercase and lowercase letters). Method variations prefixed with [code]r[/code] ([method rfind], [method rsplit], etc.) are reversed, and start from the end of the string, instead of the beginning.
8+
Some string methods have corresponding variations. For example, string-comparison methods are [b]case-sensitive[/b] by default but have [b]case-insensitive[/b] variations suffixed with [code]n[/code] ([method countn], [method findn], [method replacen], etc.) which treat uppercase and lowercase letters as equal. Another example is method variations prefixed with [code]r[/code] ([method rfind], [method rsplit], etc.) where processing is reversed, starting from the end of the string instead of the beginning.
99
To convert any [Variant] to or from a string, see [method @GlobalScope.str], [method @GlobalScope.str_to_var], and [method @GlobalScope.var_to_str].
1010
[b]Note:[/b] In a boolean context, a string will evaluate to [code]false[/code] if it is empty ([code]""[/code]). Otherwise, a string will always evaluate to [code]true[/code].
1111
</description>
@@ -132,7 +132,7 @@
132132
<return type="bool" />
133133
<param index="0" name="what" type="String" />
134134
<description>
135-
Returns [code]true[/code] if the string contains [param what]. In GDScript, this corresponds to the [code]in[/code] operator.
135+
Returns [code]true[/code] if the string contains [param what] (case-sensitive). In GDScript, this corresponds to the [code]in[/code] operator. See [method containsn] for a case-insensitive version.
136136
[codeblocks]
137137
[gdscript]
138138
print("Node".contains("de")) # Prints true
@@ -144,15 +144,15 @@
144144
GD.Print("team".Contains("I")); // Prints False
145145
[/csharp]
146146
[/codeblocks]
147-
If you need to know where [param what] is within the string, use [method find]. See also [method containsn].
147+
If you need to know where [param what] is within the string, use [method find].
148148
</description>
149149
</method>
150150
<method name="containsn" qualifiers="const">
151151
<return type="bool" />
152152
<param index="0" name="what" type="String" />
153153
<description>
154-
Returns [code]true[/code] if the string contains [param what], [b]ignoring case[/b].
155-
If you need to know where [param what] is within the string, use [method findn]. See also [method contains].
154+
Returns [code]true[/code] if the string contains [param what], [b]ignoring case[/b]. See [method contains] for a case-sensitive version.
155+
If you need to know where [param what] is within the string, use [method findn].
156156
</description>
157157
</method>
158158
<method name="count" qualifiers="const">
@@ -161,7 +161,7 @@
161161
<param index="1" name="from" type="int" default="0" />
162162
<param index="2" name="to" type="int" default="0" />
163163
<description>
164-
Returns the number of occurrences of the substring [param what] between [param from] and [param to] positions. If [param to] is 0, the search continues until the end of the string.
164+
Returns the number of case-sensitive occurrences of the substring [param what] between [param from] and [param to] positions. If [param to] is 0, the search continues until the end of the string. See [method countn] for a case-insensitive version.
165165
</description>
166166
</method>
167167
<method name="countn" qualifiers="const">
@@ -170,7 +170,7 @@
170170
<param index="1" name="from" type="int" default="0" />
171171
<param index="2" name="to" type="int" default="0" />
172172
<description>
173-
Returns the number of occurrences of the substring [param what] between [param from] and [param to] positions, [b]ignoring case[/b]. If [param to] is 0, the search continues until the end of the string.
173+
Returns the number of occurrences of the substring [param what] between [param from] and [param to] positions, [b]ignoring case[/b]. If [param to] is 0, the search continues until the end of the string. See [method count] for a case-sensitive version.
174174
</description>
175175
</method>
176176
<method name="dedent" qualifiers="const">
@@ -183,7 +183,7 @@
183183
<return type="bool" />
184184
<param index="0" name="text" type="String" />
185185
<description>
186-
Returns [code]true[/code] if the string ends with the given [param text]. See also [method begins_with].
186+
Returns [code]true[/code] if the string ends with the given [param text] (case-sensitive). See also [method begins_with].
187187
</description>
188188
</method>
189189
<method name="erase" qualifiers="const">
@@ -215,7 +215,7 @@
215215
<param index="0" name="what" type="String" />
216216
<param index="1" name="from" type="int" default="0" />
217217
<description>
218-
Returns the index of the [b]first[/b] occurrence of [param what] in this string, or [code]-1[/code] if there are none. The search's start can be specified with [param from], continuing to the end of the string.
218+
Returns the index of the [b]first[/b] case-sensitive occurrence of [param what] in this string, or [code]-1[/code] if there are none. The search's start can be specified with [param from], continuing to the end of the string. See [method findn] for a case-insensitive version.
219219
[codeblocks]
220220
[gdscript]
221221
print("Team".find("I")) # Prints -1
@@ -240,7 +240,7 @@
240240
<param index="0" name="what" type="String" />
241241
<param index="1" name="from" type="int" default="0" />
242242
<description>
243-
Returns the index of the [b]first[/b] [b]case-insensitive[/b] occurrence of [param what] in this string, or [code]-1[/code] if there are none. The starting search index can be specified with [param from], continuing to the end of the string.
243+
Returns the index of the [b]first[/b] [b]case-insensitive[/b] occurrence of [param what] in this string, or [code]-1[/code] if there are none. The starting search index can be specified with [param from], continuing to the end of the string. See [method find] for a case-sensitive version.
244244
</description>
245245
</method>
246246
<method name="format" qualifiers="const">
@@ -441,7 +441,7 @@
441441
<return type="bool" />
442442
<param index="0" name="text" type="String" />
443443
<description>
444-
Returns [code]true[/code] if all characters of this string can be found in [param text] in their original order. This is not the same as [method contains].
444+
Returns [code]true[/code] if all characters of this string can be found in [param text] (case-sensitive) in their original order. This is not the same as [method contains]. See [method is_subsequence_ofn] for a case-insensitive version.
445445
[codeblock]
446446
var text = "Wow, incredible!"
447447

@@ -456,7 +456,7 @@
456456
<return type="bool" />
457457
<param index="0" name="text" type="String" />
458458
<description>
459-
Returns [code]true[/code] if all characters of this string can be found in [param text] in their original order, [b]ignoring case[/b]. This is not the same as [method containsn].
459+
Returns [code]true[/code] if all characters of this string can be found in [param text] in their original order, [b]ignoring case[/b]. This is not the same as [method containsn]. See [method is_subsequence_of] for a case-sensitive version.
460460
</description>
461461
</method>
462462
<method name="is_valid_ascii_identifier" qualifiers="const">
@@ -624,14 +624,14 @@
624624
<return type="bool" />
625625
<param index="0" name="expr" type="String" />
626626
<description>
627-
Does a simple expression match (also called "glob" or "globbing"), 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].
627+
Does a simple expression match (also called "glob" or "globbing"), where [code]*[/code] matches zero or more arbitrary characters and [code]?[/code] matches any single character except a period ([code].[/code]). String matching is case-sensitive. See [method matchn] for a case-insensitive version. An empty string or empty expression always evaluates to [code]false[/code].
628628
</description>
629629
</method>
630630
<method name="matchn" qualifiers="const">
631631
<return type="bool" />
632632
<param index="0" name="expr" type="String" />
633633
<description>
634-
Does a simple [b]case-insensitive[/b] 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].
634+
Does a simple [b]case-insensitive[/b] expression match, where [code]*[/code] matches zero or more arbitrary characters and [code]?[/code] matches any single character except a period ([code].[/code]). See [method match] for a case-sensitive version. An empty string or empty expression always evaluates to [code]false[/code].
635635
</description>
636636
</method>
637637
<method name="md5_buffer" qualifiers="const">
@@ -790,7 +790,7 @@
790790
<param index="0" name="what" type="String" />
791791
<param index="1" name="forwhat" type="String" />
792792
<description>
793-
Replaces all occurrences of [param what] inside the string with the given [param forwhat].
793+
Replaces all case-sensitive occurrences of [param what] inside the string with the given [param forwhat]. See [method replacen] for a case-insensitive version.
794794
</description>
795795
</method>
796796
<method name="replace_char" qualifiers="const">
@@ -814,7 +814,7 @@
814814
<param index="0" name="what" type="String" />
815815
<param index="1" name="forwhat" type="String" />
816816
<description>
817-
Replaces all [b]case-insensitive[/b] occurrences of [param what] inside the string with the given [param forwhat].
817+
Replaces all [b]case-insensitive[/b] occurrences of [param what] inside the string with the given [param forwhat]. See [method replace] for a case-sensitive version.
818818
</description>
819819
</method>
820820
<method name="reverse" qualifiers="const">
@@ -828,15 +828,15 @@
828828
<param index="0" name="what" type="String" />
829829
<param index="1" name="from" type="int" default="-1" />
830830
<description>
831-
Returns the index of the [b]last[/b] occurrence of [param what] in this string, or [code]-1[/code] if there are none. The search's start can be specified with [param from], continuing to the beginning of the string. This method is the reverse of [method find].
831+
Returns the index of the [b]last[/b] case-sensitive occurrence of [param what] in this string, or [code]-1[/code] if there are none. The search's start can be specified with [param from], continuing to the beginning of the string. This method is the reverse of [method find]. See [method rfindn] for a case-insensitive version.
832832
</description>
833833
</method>
834834
<method name="rfindn" qualifiers="const">
835835
<return type="int" />
836836
<param index="0" name="what" type="String" />
837837
<param index="1" name="from" type="int" default="-1" />
838838
<description>
839-
Returns the index of the [b]last[/b] [b]case-insensitive[/b] occurrence of [param what] in this string, or [code]-1[/code] if there are none. The starting search index can be specified with [param from], continuing to the beginning of the string. This method is the reverse of [method findn].
839+
Returns the index of the [b]last[/b] [b]case-insensitive[/b] occurrence of [param what] in this string, or [code]-1[/code] if there are none. The starting search index can be specified with [param from], continuing to the beginning of the string. This method is the reverse of [method findn]. See [method rfind] for a case-sensitive version.
840840
</description>
841841
</method>
842842
<method name="right" qualifiers="const">

0 commit comments

Comments
 (0)