Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Jer
- Posts: 177
- Joined: 23 Nov 2014 17:13
- Location: California USA
#1
Post
by Jer » 10 Sep 2020 22:06
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
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
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#2
Post
by Squashman » 10 Sep 2020 22:28
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.
-
Jer
- Posts: 177
- Joined: 23 Nov 2014 17:13
- Location: California USA
#3
Post
by Jer » 11 Sep 2020 18:43
String substitution is not case sensitive. Squashman, thank you for that lesson.