I am writing to ask a question about a response provided for a post from 2017 - linked. The original poster wanted to know how to extract all text from a string that came after a specific character (in this case $). The simplest solution which was given is the code shown below. However, I am unclear about how this code actually works - specifically the line set "result=%str:$=" & set "result=%"
. I have done some testing and found that the variable "result" has a value when called within the line (between the two commands linked by the &) and a different value when called after the line. But I also noticed you will generate an error if you try to remove the command after the & and call the variable on a lower line. You will also get an error if you remove the second command but still try to call the variable within the line. The two commands are clearly working in tandem but I can't figure out what they are communicating or how this piece of code connects the two. Can someone please explain what process is actually occurring to achieve this result?
How to extract text after $ in batch file?
set "str=Te$ting thi$ $cript for $zero"
set "result=%str:$=" & set "result=%"
echo %result%