dbenham wrote:You can use string search and replace to do a case insensitive search. Replace your search term with nothing, and see if the result matches the original:
Code: Select all
set "str=-debug -verbose -normi -homedir -repo"
if "%str:-debug=%" neq "%str%" (echo -verbose found) else (echo -verbose not found)
Dave Benham
I like it, quite a lot.
I have two immediate uses for it,
but for one use it has a killer bug that I had to fix.
It MIGHT be relevant to this topic also.
I have two specific command words, e.g. "DoThis" and "DoThat".
I have a file with 8,000 lines,
and I need to reject each line which starts with some other word,
e.g. words such as "dothis DOTHAT DoNowt Dot that"
In the following my first attempt was Demo1,
which worked correctly for the first three words,
but the last two illegal words were partial matches for legal words and were wrongly validated.
My second attempt Demo2 uses # as boundary markers for the legal words, and all the results are good.
You can of course use any boundary markers that do not appear within the legal words.
Code: Select all
@echo off & setlocal EnableDelayedExpansion
call :demo1 "DoThis DoThat" "dothis DOTHAT DoNowt Dot that"
call :demo2 "#DoThis# #DoThat#" "dothis DOTHAT DoNowt Dot that"
:pause
exit/b
:Demo1
set str=%~1
echo( & echo( validating random {%~2} against legal {%~1}
for %%a in (%~2) do (
if "!str:%%a=!"=="%str%" (echo rejected %%a) else (echo validated %%a )
)
exit /b
:Demo2
set str=%~1
echo( & echo( validating random {%~2} against legal {%~1}
for %%a in (%~2) do (
if "!str:#%%a#=!"=="%str%" (echo rejected %%a) else (echo validated %%a )
)
exit /b
Code results :-
Code: Select all
E:\T\CCleaner\v313\WinApp_2>x
validating random {dothis DOTHAT DoNowt Dot that} against legal {DoThis DoThat}
validated dothis
validated DOTHAT
rejected DoNowt
validated Dot
validated that
validating random {dothis DOTHAT DoNowt Dot that} against legal {#DoThis# #DoThat#}
validated dothis
validated DOTHAT
rejected DoNowt
rejected Dot
rejected that
E:\T\CCleaner\v313\WinApp_2>
Regards
Alan