godot
godot copied to clipboard
[3.x] C#: Deprecate string extensions that will be removed in 4.x
- Equivalent of #67031 for 3.x that avoids breaking compatibility.
- Deprecated
Length
in favor of thestring.Length
property. - Deprecated
Insert
in favor of the existing instance method with the same signature. - Deprecated
Erase
in favor ofStringBuilder.Remove
. - Deprecated
ToLower
andToUpper
in favor of the instance methods with the same signature. - Deprecated
BeginsWith
in favor ofstring.StartsWith
. - Deprecated
EndsWith
in favor of the instance method with the same signature. - Deprecated
Empty
in favor ofstring.IsNullOrEmpty
. - Deprecated
OrdAt
in favor of thestring[int]
indexer. - Deprecated
LStrip
andRStrip
in favor ofstring.TrimStart
andstring.TrimEnd
.
Note About the deprecation of
LStrip
/RStrip
, these methods don't trim when thechars
parameter is "" (no characters) but thestring.TrimStart
/string.TrimEnd
methods trim whitespace when thetrimChars
parameter is an empty array. This behavior change is probably not a common scenario but it's worth taking in consideration:
string str = "Hello World";
str.TrimStart(); // Removes whitespace
str.LStrip(""); // Removes nothing
Note About
FindLast
, the C++ method was removed in 4.0, in 3.x its implementation was replaced with a call toRFind
so they are the same thing but it doesn't break compatibility. In C#FindLast
is implemented as a call tostring.LastIndexOf
, whileRFind
is a PInvoke. This means recommending users in 3.x to switch toRFind
will result in worse performance. Should we instead recommend users to switch tostring.LastIndexOf
even ifRFind
still exists in 4.0? In 4.0 theRFind
implementation has been replaced by a call tostring.LastIndexOf
but I'm not sure we want to make the same change in 3.x.