Random beginner-question: replace and keep replaced

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

Hi everyone,

my Label get’s the digit-entries from another Label and replaces them with *s.

var array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]

func _on_aLabel_labelNotEmpty(): # triggers on each entry

	text = get_node(a_label).text.replace(0, "*")
	text = get_node(a_label).text.replace(1, "*")
	text = get_node(a_label).text.replace(2, "*")

This works for the last number, 2 in this case, but not for the others before.

Putting some yield time in between the lines shows that actually on each entry the whole sequence is being worked through. However, after changing the number to * it changes back to the digit with the next one in line…

How can the * be kept once replaced?
Or is there a more direct way to have digits replaced with * generally in the first place? (I bet!)

Well, it appears there were just some " " missing. This works:

text = text.replace("0", "*")

text = text.replace("1", "*")

text = text.replace("2", "*")

text = text.replace("3", "*")


And that’s it. I’m sure RegEx could spare me some lines, but this does the trick for my little project.

pferft | 2021-04-14 11:17

:bust_in_silhouette: Reply From: exuin

Answered on Reddit.