Dos String manipulation

  • Thread starter Thread starter charles ling
  • Start date Start date
C

charles ling

This may seem incredibly simple to the experienced -

I need to be able to Partial field (or substring) a
variable within a simple dos batch file.

eg
set %var=12345678
I want to extract say the 5th and 6th digits and assign to
another variable. I can't seem to find a standard cmd to
perform this simple task (am I just stupid??)

any suggestions would be gratefully received
 
set var=12345678
set vara=%var:~4,2%

where 4 is the (zero based) starting point and 2 is the number of chars you
want

You will find a lot of this type of info at
microsoft.public.win2000.cmdprompt.admin

(don't feel stupid--it's only easy after you find out how)
 
charles said:
This may seem incredibly simple to the experienced -

I need to be able to Partial field (or substring) a
variable within a simple dos batch file.

eg
set %var=12345678
I want to extract say the 5th and 6th digits and assign to
another variable. I can't seem to find a standard cmd to
perform this simple task (am I just stupid??)
Hi

You can use the set command for this:

'--------------------8<----------------------
@echo off
set var=12345678
set extract=%var:~4,2%
echo %extract%
'--------------------8<----------------------

Note that the newsgroup
microsoft.public.win2000.cmdprompt.admin is a very good newsgroup
for command line/batch related questions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top