On 25.08.2017 12:35, John Gray wrote:
> Herbert: your method can suffer from "the trailing blank problem"
> (certainly using NOTEPAD) unless in each SET statement you enclose
> everything after SET in double-quotes (or otherwise).
I don't think this is a "problem". If you write a trailing space,
then the batch can't just ignore it. But you always can add a &
to ignore unwanted trailing spaces:
for /l %%i in (1,1,32) do call set original=%%original:~1%%-&
> Interesting that the FOR loop terminates early!
The "for" doesn't terminate early, but replacing a "-" by an
other "-" doesn't change anything. But there is a problem if you
don't know the upper limit for the length of the word. In this
case you have to check and loop if necessary:
@echo off
set original=Single Word
echo %original%
:loop
for /l %%i in (1,1,32) do call set original=%%original:~1%%-&
set a=%original:-=%&if defined a goto :loop
echo %original%
But then you also can set the loop count in the for loop to 1
(which means removing the for loop):
@echo off
set original=Single Word
echo %original%
:loop
set original=%original:~1%-&set a=%original:-=%&if defined a goto :loop
echo %original%