removing a character from a string

Im writing a script where i need to take unix names of files or folders that may come in the form “folder/” and use them in an alias object.
therefore i need to be able to remove the trailing / from the name. I could make a loop the copies every character of the string except the last one, 1 at a time to a new variable, but there must be a better way… any ideas?

set test to POSIX path of (path to desktop)

set test to text 1 thru -2 of test

awesome, thanks