How to remove a specific char from a string?

Godot Version

4.2.1

Question

I have a string and would like to remove a specific char from it, but I can’t be sure it is at the same index in all cases.
This is want I want to acomplish:

'0.1234' -> '01234'

From what I could find I should use .lstrip() to remove the ‘.’ , but it doesn’t seem to work.

sub_string = '0.1234'
sub_string = sub_string.lstrip('.')
print(sub_string)

#prints:
'0.1234'

What I’m I overlooking? Is this the wrong approach?

String.lstrip() removes the characters from the beginning of the string not the first appearance of them.

Use String.replace() to remove them like:

sub_string = '0.1234'
sub_string = sub_string.replace('.', '')
3 Likes

Thanks! Your wording is way more clear than the docs

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.