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,787 of 68,980    |
|    JJ to Tom Del Rosso    |
|    Re: Get String Length    |
|    07 Sep 21 18:24:17    |
      From: jj4public@gmail.com              On Mon, 6 Sep 2021 12:45:46 -0400, Tom Del Rosso wrote:       > JJ wrote:       >> On Sun, 5 Sep 2021 12:53:16 -0400, Tom Del Rosso wrote:       >>> JJ wrote:       >>>> On Fri, 3 Sep 2021 03:07:18 -0400, Tom Del Rosso wrote:       >>>>> JJ wrote:       >>>>>> On Thu, 2 Sep 2021 03:08:01 -0400, Tom Del Rosso wrote:       >>>>>>>       >>>>>>> What does HasStr do? Find a substring?       >>>>>>       >>>>>> Yes. A sub to check the existence of a substring when the index of       >>>>>> the substring doesn't matter. It's basically just a sub which       >>>>>> finds the index of a substring.       >>>>>       >>>>> So you're thinking of doing it this way?       >>>> [snip]       >>>>       >>>> Huh? Why are you using string lengths to check the existence of a       >>>> substring?       >>>       >>> I don't know! I thought that was what you were suggesting when you       >>> said:       >>>       >>> "The method could be used as a fast `HasStr` sub. :)"       >>       >> By "method", I meant the algorithm. Not the sub itself as is.       >>       >> But nevermind though, cause I found out that the divide-and-conquer       >> algorithm can't be used as a faster substring search than sequential       >> one.       >       > If the objective is to find exactly where the substring exists then it       > could actually be faster for a long string.       >       > I mean using the asterisk in string substitution like below, and testing       > the length of the result. Even more so if you already know the length of       > the original string.       >       > call set poststring=%%string:*%substring%=%%              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              --- 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