This function takes a string and removes any trailing substring that matches the supplied trail-parameter.
If the substring is repeated several times in the trail of the string, then all of these occurrences will be removed.