title: How to output exclamation mark with EnabledDelayedExapnsion?
body: <p>I am working on editing an XML file, and approximately the first 10 lines are comments. And for xml comments are in the form</p>
  
  <pre><code>&lt;!--  COMMENT HERE   --&gt;
  </code></pre>
  
  <p>But when using my code it does not output that ! mark, which screws up the comments in the xml. I understand that the ENABLEDELAYEDEXPANSION is doing this because it thinks the exclamation mark is expanding a variable. How could I get this to work? </p>
  
  <p>Here is my code below</p>
  
  <pre><code>setlocal ENABLEDELAYEDEXPANSION
  
  set line=0
  
  FOR /f "usebackqdelims=" %%a in ("%filename2%") do (
      set /a line = !line!+1 
      if !line!==39 (echo REPLACED TEXT39&gt;&gt;%tempfile%
  )else if(!line!==45 (echo REPLACED TEXT45&gt;&gt;%tempfile%
  )else (echo %%a&gt;&gt;%tempfile%
  ))
  </code></pre>
  
  <p><em>EDIT1</em> Basically what it is supposed to do is output each line as it is, unless it is line 39 or 45. It works, except the ! marks in the comments don't get outputted and they are not comments anymore.</p>
  
  <p><em>EDIT2</em></p>
  
  <pre><code>set line=0
  
  FOR /f "usebackqdelims=" %%a in ("%filename2%") do (
  setlocal ENABLEDELAYEDEXPANSION
      set /a !line! +=1
  echo !line!
      if !line!==39 (
  echo REPLACED TEXT39&gt;&gt;%tempfile%
  endlocal
  )else if !line!==45 (
  echo REPLACED TEXT45&gt;&gt;%tempfile%
  endlocal
  )else (
  endlocal
  setlocal DISABLEDELAYEDEXPANSION
  echo %%a&gt;&gt;%tempfile%
  endlocal
  ))
  </code></pre>
  
  <p>Here is the latest code I have been using. It works the best, but now the problem is that the variable "line" is not getting updated. I have a feeling that it is because of the "endlocal". The only problem is that I need the "endlocal" there otherwise I get an error </p>
  
  <blockquote>
    <p>Maximum setlocal recursion level reached.</p>
  </blockquote>
  
  <p>The problem is, I need to alternate between enableddelayedexpansion and disabledelayedexpansion so that my exclamation marks show up properly. But to do that I need to keep up with the "endlocal" calls which i think is messing up my line variable. Any thoughts?</p>