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,794 of 68,980    |
|    Tom Del Rosso to All    |
|    Re: Get String Length    |
|    07 Sep 21 17:10:36    |
      From: fizzbintuesday@that-google-mail-domain.com              JJ wrote:       >       > Oh, I see. I didn't realize asterisk as a leading wildcard is       > supported for string replacement. That's indeed a faster way to find       > the substring offset. Thanks.       >       > Though, in a different topic but related to that asterisk wildcard...       > Although I haven't yet need to do it, is it possible to replace       > literal asterisk character itself excluding any characters preceeding       > it, using replace string substitution? I've tried escaping the       > asterisk and using double asterisks, but it doesn't work. For       > example, to replace `*` with `;`, so that e.g. `abc*def` would become       > `abc;def`.       >       > @echo off       > setlocal       > call :repesc "abc*def" result       > echo escape=%result%       > call :repdbl "abc*def" result       > echo double=%result%       > goto :eof       >       > :repesc       > set "a=%~1"       > set "%2=%a:^*=;%"       > goto :eof       >       > :repdbl       > set "a=%~1"       > set "%2=%a:**=;%"       > goto :eof       >       > Here, the result are:       >       > escape=abc*def       > double=;def              I guess you could use ** to chop off the first part of the string, then       measure its length and then reassemble it, like              set x=abc*def       set y=%x:**=;%       [...get length of x and y and x-y...]       set /a prefix_len = x_len - y_len       call set z=%%x:~0,%prefix_len%%%%y%       set z       pause                     But my first idea started in the wrong direction.       I thought of putting something before the asterisk like              set y=%x:c*=c;%              which would work if you know the letter before it is c.              To try every letter you have to use FIND to do the substitution at the       right time (or else it would change back when it got to the next       letter), like this, but it's much slower.              @echo off       set y=abc*def       set "z="       for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (        echo %y% | find "%%a*" >nul        if not errorlevel 1 (        call set z=%%y:%%a*=%%a$%%        )       )       set y       set z       pause                     --        Defund the Thought Police              --- 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