I need to sort user-input line without using output to file, just in memory, and save the result to variable:
"b" "c" "a" -> "a" "b" "c"
But the code I use produces the trailing space on each chunc:
"b" "c" "a" -> "a"[space][space]"b"[space][space]"c"[space]
For removing trailing space and building resulting variable I use some :HelpProc calling.
- Ho to avoid trailing spaces without deleting them manually?
- Maybe there is other way for building the result line, without using procedure call?
@echo off
echo Copy and paste this: "b&b" "a!a" "d%%d" "e e" "c^c"
echo/
<nul set /p="Enter string: "
set /p string=
echo/
set "SortedLine="
for /f "delims=" %%x in ('(for %%y in (%string%^) do @echo %%y^)^|sort') do (
echo Extracted: [%%x]
set "word=%%x"
call :HelpProc
)
echo/
:: Remove first space
set SortedLine=%SortedLine:~1%
echo Sorted Line: [%SortedLine%]
echo/ & pause & exit /b
:HelpProc
:: Remove trailing space
set word=%word:~0,-1%
set SortedLine=%SortedLine% %word%
exit /b