erase String doesn't work

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Liemaeu

My string s is “X1”

The string s is from the array cutted_string (s = cutted_string[0]), which was created by using the .split() function (cutted_string = a_string.split(“_”, true, 1)

If I try to erase the X:

var new_s = s.erase(0, 1)
print(new_s)

I get:

Null

But it should be

1

(as string)

What am I doing wrong?

Thanks!

:bust_in_silhouette: Reply From: exuin

Weirdly enough, erase is the only String function that doesn’t return anything. So instead the original string s is altered. Print the original string instead of new_s to get “1”.

Edit: See Core: disabled method bindings that were not compatible with the new system · Issue #43311 · godotengine/godot · GitHub

Thank you very much!

Now it works

Liemaeu | 2021-05-23 10:53