I get confused with the Windows batch way to process string and substring when it contains special characters.
From a script I obtained this variable:
echo "%longString"
which returns me:
"<p style="text-align: center;"><a class="more" href=" https://repo.anaconda.com/archive/Anaconda3-2019.10-Windows-x86_64.exe">Download</a></p><p style="text-align: center;"><a href=" https://repo.anaconda.com/archive/Anaconda3-2019.10-Windows-x86_64.exe">64-Bit Graphical Installer (462 MB)</a></p><p style="text-align: center;"><a href="https://repo.anaconda.com/archive/Anaconda3-2019.10-Windows-x86.exe">32-Bit Graphical Installer (410 MB)</a></p></div>"
And the only part that I am interested in is between a href="
and ">64-Bit Graphical
.
Then, using this similar question (but I does not contain the difficulty of special characters), I tried many combinations of the proposed solutions but every time I get unexpected result with my case because of the special characters.
I thing that a non-working example could be
@ECHO OFF
:: define the longstring
Call Set "longString=<p style="text-align: center;"><a class="more" href=" https://repo.anaconda.com/archive/Anaconda3-2019.10-Windows-x86_64.exe">Download</a></p><p style="text-align: center;"><a href=" https://repo.anaconda.com/archive/Anaconda3-2019.10-Windows-x86_64.exe">64-Bit Graphical Installer (462 MB)</a></p><p style="text-align: center;"><a href="https://repo.anaconda.com/archive/Anaconda3-2019.10-Windows-x86.exe">32-Bit Graphical Installer (410 MB)</a></p></div>"
:: Define subtrings token
Set "subsA=a href=""
Set "subsB=>64-Bit Graphical"
:: Remove part before subsA
Call set "Result=%%longString:*%subsA%=%%"
:: extract part to remove behind subsB
Call set "Remove=%%Result:*%subsB%=%%"
:: remove part behind subsB
Call set "Result=%%Result:%Remove%=%%"
Echo "%Result%"
For now my best result is using Set "subsA=href"
and Set "subsB=64-Bit"
(so it is simpler since there is no special characters in), which allows me to go through the first settings of Result
and Remove
but then because these new variables contain many special characters the last setting of Result
gives me crap.
I also tried to use For /F
and findstr
but the results where even worse.
So I eager to find any solution or/and explanations.