How to remove numbers from a string

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

This is the code I have:
$“/root/World/UI/InteractionInfoLabel”.text = get_collider().get_name()

It’s under an interaction script and basicly sets text in the screen to the name of the thing at the end of interaction raycast. It works with single object like Shotgun it works but with things that has multiple of them like ammo boxes engine automaticly gives that node a number like Ammo Box1 or Ammo Box 2 and in label it shows that number. I wanna remove it

:bust_in_silhouette: Reply From: Andrea

Unless you know in advance the length of the string you need to display (in that case you can use left() or right() method to remove the numbers), i guess you have to use something else to show it
eg use a custom “type” variable: print(raycast_collision_result.type) or using the class name of the node print(raycast_collision_result.get_class()) .

:bust_in_silhouette: Reply From: aipie

I believe the string rstrip function coul help here.

$“/root/World/UI/InteractionInfoLabel”.text = getcollider().getname().rstrip(“0123456789”)

works like a charm
IntcText.text = IntcText.text.rstrip(“0123456789”)

lukifah | 2022-09-18 22:40