One way to do it would be:
replaceAll($StringInput, ',$', '')
This will replace a comma at the end of the string (the dollar sign represents the end of the string) with nothing, or return the same string if there was no comma at the end.