Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Let me introduce you to my friend, the <a href="http://ss64.com/nt/for.html" rel="nofollow">for loop</a>. Save all the lines the user entered into a single file. I'll call this file <code>input.txt</code>. Use a <code>for</code> loop with the <code>/f</code> switch and the <code>delims=</code> option to loop through every line in the file, and store the lines in the variable <code>%%i</code>. Without <code>delims=</code>, it'd read only until the first whitespace character.</p> <p>For each line it reads, do your text substitution. The "gotcha" with batch programming is when you set variables inside a <code>for</code> loop, you have to add the line <code>setlocal enabledelayedexpansion</code> at the top of your file, and use <code>!</code> instead of <code>%</code> to access the variable contents.</p> <pre><code>@echo off setlocal enabledelayedexpansion for /f "delims=" %%i in (input.txt) do ( echo translating "%%i"... ^&lt;insert fake delay here^&gt; set var=%%i set var=!var:a=1 ! set var=!var:b=2 ! set var=!var:c=3 ! set var=!var:d=4 ! set var=!var:e=5 ! set var=!var:f=6 ! set var=!var:g=7 ! set var=!var:h=8 ! set var=!var:i=9 ! set var=!var:j=10 ! set var=!var:k=11 ! set var=!var:l=12 ! set var=!var:m=13 ! set var=!var:n=14 ! set var=!var:o=15 ! set var=!var:p=16 ! set var=!var:q=17 ! set var=!var:r=18 ! set var=!var:s=19 ! set var=!var:t=20 ! set var=!var:u=21 ! set var=!var:v=22 ! set var=!var:w=23 ! set var=!var:x=24 ! set var=!var:y=25 ! set var=!var:z=26 ! echo !var! ) </code></pre> <p>If <code>input.txt</code> has these contents:</p> <pre><code>programable this is line 2 third line </code></pre> <p>Then the output would look like this:</p> <pre><code>C:\batch&gt;encode.cmd translating "programable"... &lt;insert fake delay here&gt; 16 18 15 7 18 1 13 1 2 12 5 translating "this is line 2"... &lt;insert fake delay here&gt; 20 8 9 19 9 19 12 9 14 5 2 translating "third line"... &lt;insert fake delay here&gt; 20 8 9 18 4 12 9 14 5 </code></pre> <p>As you can see, I left out the fake delay. I like my programs fast. :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload