I got a String like:
"Hello.Test.Trash"
or "Hello.Test.Computer.Trash"
or "Haha.Yeah.Space.Car.Trash"
I want to be able, removing the last word “Trash“, which is always the same including the preceding dot:
"Hello.Test"
"Hello.Test.Computer"
"Hello.Yeah.Space.Car"
What would be the best/cleanest way to do that?
If you have only one occurrence of ‘.Trash’ at the end:
If ‘.Trash’ can also be in the middle of the string, and you don’t want to replace that: