Page 1 of 1

Case sensitive comparison-why doesn't this work?

Posted: 10 Sep 2020 22:06
by Jer
I can't see why the code below does not give the results I expect,
give one match in a case sensitive comparison. The code represents
an issue in a larger script. I'm probably confused and need expert help :roll:
Yes, I read /? IF
Jerry

Code: Select all

@echo Off
setlocal EnableDelayedExpansion
set "string=a"
call :myfun string

set "string=A"
call :myfun string

endlocal & exit /b

:myfun
setlocal EnableDelayedExpansion
set "instring=!%~1!"
If "%instring:a=%"=="%instring%" (echo a not found in %instring%) Else echo found a in %instring%
If "%instring:A=%"=="%instring%" (echo A not found in %instring% ) Else echo found A in %instring%
endlocal & exit /b
found a in a
found A in a
found a in A
found A in A

Re: Case sensitive comparison-why doesn't this work?

Posted: 10 Sep 2020 22:28
by Squashman
String substitution is not case sensitive.

Code: Select all

H:\>set "string=aaaa"

H:\>echo %string:A=A%
AAAA
So in your case it will always remove it.

Re: Case sensitive comparison-why doesn't this work?

Posted: 11 Sep 2020 18:43
by Jer
String substitution is not case sensitive. Squashman, thank you for that lesson.