You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If count is 1 or more, it will be taken into account, otherwise it will not matter and let you do unlimited replacements.
Currently this method only takes what to replace and forwhat to replace it with, and replaces everything that matches what. This is cool, but sometimes limiting, especially when compared to a language like Python. (https://www.w3schools.com/python/ref_string_replace.asp)
Sure, this is easy to bypass in my specific case, but considering how scripting languages see it as a necessary feature, i see no problem with having it, plus the optionality of the new parameter makes it compatible.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
A non-breaking change that improves the usability of
String.replace()
by adding an optional parametercount
which limits how many replacements will happen, unlimited by default. (https://docs.godotengine.org/en/stable/classes/class_string.html#class-string-method-replace)If
count
is 1 or more, it will be taken into account, otherwise it will not matter and let you do unlimited replacements.Currently this method only takes
what
to replace andforwhat
to replace it with, and replaces everything that matcheswhat
. This is cool, but sometimes limiting, especially when compared to a language like Python. (https://www.w3schools.com/python/ref_string_replace.asp)Other languages also have this feature built-in, like Lua. (https://www.luadocs.com/docs/functions/string/gsub) And JavaScript, but flipped on its head. (https://www.w3schools.com/jsref/jsref_replace.asp)
The specific case when i found this limiting was a creative solution to a Leetcode problem. (https://leetcode.com/problems/maximum-69-number/)
My GDScript solution looks like this:
And the Python translation for Leetcode to understand:
But in Python i can also just do this:
Sure, this is easy to bypass in my specific case, but considering how scripting languages see it as a necessary feature, i see no problem with having it, plus the optionality of the new parameter makes it compatible.
Beta Was this translation helpful? Give feedback.
All reactions