Delete last word on string after space

Hello, i have an automation problem

so I have a several product name which I want the robot to remove the last word in the product name (after space)
for example:
Reinforced Steel Bar
i want to delete the last word (“bar”) so it will become “Reinforced Steel”
Mirror (new)
i want to delete the last word ("(new)") so it will become “Mirror”

So how can i achieve this?
Thank you in advance

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Replace(yourString,"\s\S+$","")

Regards,

1 Like

Hi @Fauzan_Marantama ,

Besides @Yoichi’s regex solution, another possible way to solve the issue would be:

stringVariable.Replace(" "&stringVariable.Split(" "c).Last,"")

Best regards,
Marius

2 Likes