I'm trying to implement a truncation in my script, which is easy enough, but I need to make the overall script smart enough to remove the last character if it happens to be a space.
For instance, if I have the following code:
variable = "SAMPLE NAME"
truncVar = variable[:7]
This ends up returning "SAMPLE ", which is right, but there's a space at the end of the string. I need the script to check for that space, and delete it if it's there, otherwise leave the last character. I can't just reduce the truncated value since the actual names in the variables will vary widely.
Working Script based on correct answer:
variable = "This is a test variable"
trunc = variable[:10].strip()
result = "'" + trunc + "'"
'This is a' # The strip operation removed the ending space, but it left all others