home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch.nt      Fun with Windows NT batch files      68,980 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 67,026 of 68,980   
   Herbert Kleebauer to John Gray   
   Re: Transform string to the same number    
   25 Aug 17 14:34:31   
   
   From: klee@unibwm.de   
      
   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%   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca