We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
String.invert()
reverse()
Plugins
I need to invert a string but I can't to do this simply and efficient.
Adding String.invert()/String.reverse() would solve the problem
String.reverse()
The method would return new inverted string "hello".invert() would give "olleh"
"hello".invert()
"olleh"
There are some workrounds, for example
static func invert_string(s:String)->String: var chars_pool = PoolStringArray() var length = s.length() chars_pool.resize(length) for i in length: chars_pool[i] = s[i] chars_pool.invert() return chars_pool.join("")
This doesn't look efficient tho
Inverting strings is quite frequent task when working with text. For example in Python you can use [::-1] to do this.
[::-1]
The text was updated successfully, but these errors were encountered:
Updated the workaround example. It still requires using loop in gdscript. First of all I tried split() but it doesn't work with empty delimiter.
split()
Sorry, something went wrong.
First of all I tried split() but it doesn't work with empty delimiter.
See godotengine/godot#21699 which was rejected.
Edit: This behavior works in 4.0 and later though.
String.reverse
I also want to suggest this trivial workaround in 4.x:
func reverse(arg: String) -> String: var arr := arg.to_utf32_buffer().to_int32_array() arr.reverse() return arr.to_byte_array().get_string_from_utf32()
Successfully merging a pull request may close this issue.
Describe the project you are working on
Plugins
Describe the problem or limitation you are having in your project
I need to invert a string but I can't to do this simply and efficient.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Adding
String.invert()
/String.reverse()
would solve the problemDescribe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
The method would return new inverted string
"hello".invert()
would give"olleh"
If this enhancement will not be used often, can it be worked around with a few lines of script?
There are some workrounds, for example
This doesn't look efficient tho
Is there a reason why this should be core and not an add-on in the asset library?
Inverting strings is quite frequent task when working with text. For example in Python you can use
[::-1]
to do this.The text was updated successfully, but these errors were encountered: