How to remove the last character of a string if I know what the character is in AppleScript?

So basically I was messing around with AppleScript and created a variable based on the app's path and it always has a forward slash at the end that I don't want. See my other question for more info. Basically thePath is set to /Applications/MyEpicApp.app/ with that extra / I don't want.

What's the "opposite" of "sometext" & someVariable in AppleScript?

Many thanks in advance, I appreaciate every piece of information.


Solution 1:

To have a portion of the string returned, the format would be:

set StringVariable2 to (characters n through n of StringVariable1) as string

n is the character number of the string starting at 1
as string is important or otherwise you get a list of single characters returned

Just make sure that whenever you parse any text, list or other item inside AppleScript to have text item delimiters at their default value (an empty list {}) unless you want to include those characters in the result as well.

In your example of removing the last character, it would be:

set StringVariable2 to (characters 1 through ((length of StringVariable1) - 1) of StringVariable1) as string