Hi, I have obtained a way to trim leading and trailing spaces in a string. The answer is below, in the code snippet. This script returns a string in all cases, even if the input is all spaces within quotes, where the script will return "".
Now there is an input that is problematic for me. Pass it " 12 "1" 23 "", and the function will fail. However, if you only run the logic for removing the leading spaces, the input works.
So you get points if:
1. you can explain to me why this is happening,
2. you can provide a solution to the failure in the trim trailing spaces segment,
3. you could make the input appear stripped of leading and trailing spaces as the output for the following batch script:
FOR %%a IN ("%~1", "%~2", "%~3", "%~4") DO (
for /F "usebackq delims=" %%s in (`TrimLeadingAndTrailingSp
aces.bat %%a`) do echo %%s
Best of luck,
echo What it looks like before [%string%]
if "%string:~0,1%"==" " (
echo to trailing
if "%string:~-1%"==" " (
echo What it looks like afterwards [%string%]