I'm trying to trim whitespace from a string variable. I've figured out how to left trim, but can't figure out how to right trim. There are some examples on the web, but to work they make assumptions like the maximum length of string, or that it won't contain 2 # symbols together. I can't make this assumption so would need it to be fail safe.
In short, I need a solution to trim spaces from the right end of the string.
My code is shown below, with the left trim working.
rem --- Set variable and remove any surrounding quotes
rem --- Remove whitespace at left
for /F "tokens=*" %%s in ("%_string%") do set _trimmed=%%s
rem --- Remove whitespace at right