title: DOS Substring where Length is a Variable
body: <p>I'm trying to extract a substring, from a variable, in a DOS batch script.  As I understand it, one does this with a statement like the following:  </p>
  
  <pre><code>set substring=%original_string:~2,3%  
  </code></pre>
  
  <p>Where 2 would be a zero-based offset, and 3 would be the length of the substring to be extracted.  So far, so good, right?</p>
  
  <p>But, I need my length to be a variable, not a explicit number.  I'm almost sure this can be done, but the proper syntax is eluding me :-(</p>
  
  <p>What I have tried is...</p>
  
  <pre><code>set string=string
  
  set length=3
  
  set substring=%string:~0,%length%%
  
  echo substring is: %substring%
  </code></pre>
  
  <p>What I get is...</p>
  
  <pre><code>substring is: length%
  </code></pre>
  
  <p>I've tried removing 1 set of percent signs, but...  no good.</p>
  
  <p>Does anyone know if and how I can do what I want???</p>
  
  <p>thx!</p>