I’ve tried to find the solution to this particular challenge for countless hours. Not sure if I’m doing this right, but can the answer be found using subSequence or maybe subStringBeforeLast?

I’ve been reading the documentation and so far been unsuccessful, otherwise are loops the only way to solve this problem?