title: Batch - Set/Reset parameters calling subroutine with exclamation mark (!) and delayed expansion?
body: <p>I have 2 Locals using delayed expansion. The 1. Local calls a subroutine which includes the 2. Local which defines 2 variables and set the values of those as the parameter values using <code>FOR /F ...</code>. This works fine as long as the string do not include one or more exclamation marks. The following working script shows the issue:</p>
  
  <pre><code>@ECHO OFF
  SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
  
      CALL :get_substrings testString substr
      ECHO Inside 1. local:
      ECHO !testString!
      ECHO !substr!
  
      EXIT /B 0
  ENDLOCAL
  
  
  :get_substrings
      SETLOCAL ENABLEDELAYEDEXPANSION
  
      SET string="World^! wasserschutzpolizei^!"
      SET substring="Hello^!"
      ECHO Inside get_substrings:
      ECHO !string!
      ECHO !substring!
  
      FOR /F "delims=" %%s IN ("!string!") DO FOR /F "delims=" %%b IN ("!substring!") DO (
          ENDLOCAL &amp; SET "%1=%%s" &amp; SET "%2=%%b" &amp; EXIT /B 0
      )
  EXIT /B 0
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Inside get_substrings:
  "World! wasserschutzpolizei!"
  "Hello!"
  Inside 1. local:
  "World"
  "Hello"
  </code></pre>
  
  <p>Expected:</p>
  
  <pre><code>Inside get_substrings:
  "World! wasserschutzpolizei!"
  "Hello!"
  Inside 1. local:
  "World! wasserschutzpolizei!"
  "Hello!"
  </code></pre>
  
  <p>If you remove the exclamation marks in <code>string</code> and <code>substring</code> the script works as expected.</p>
  
  <p>Because this is just an Example consider...</p>
  
  <ol>
  <li>Not using delayed expansion is not an option and also... </li>
  <li>Using one Local is undesirable.</li>
  </ol>
  
  <p>Of course, if one or even both things are REALLY required and there is no other way I accept other answers pointing that out.</p>
  
  <p>So...</p>
  
  <ol>
  <li>How can get the values with exclamation mark in the 1. local like i showed in the <em>Expected</em> part?</li>
  <li>Why doesn't it work with the current way of setting the param values?</li>
  </ol>
  
  <p>Appreciate your help!</p>