Link to home
Start Free TrialLog in
Avatar of Elena Quinn
Elena Quinn

asked on

Extracting a string from another string in MS-DOS

I am trying to take an input string, extract the second through ninth character and use it as a directory name.  This is real DOS I'm talking about, not a shell in Windows. This is real boot up to a C:\ prompt DOS from a Windows 98 boot disc.  Windows is non-existent on this system.

I tried:

set test=123456789012
echo %test:~1,9%

Open in new window


But it just returns "ECHO is on"

I want to see 23456789, so I can then use it to create a directory named 23456789.

The end goal here is to create a batch file which I can launch with the string as an argument.  Then I would create a directory and take the results of the batch file and copy them into that directory.  Every time I run this particular test, it will overwrite the results, so I need to move them into a meaningful directory name each time.
Avatar of NVIT
NVIT
Flag of United States of America image

I don't have a problem with just this in the entire file:
set test=123456789012
echo %test:~1,9%

Open in new window


...it shows as expected:
234567890

Open in new window


Maybe adding setlocal enabledelayedexpansion at the top will help you:
@echo off
setlocal enabledelayedexpansion

set test=123456789012
echo %test:~1,9%

Open in new window

Avatar of Elena Quinn
Elena Quinn

ASKER

It doesn't show as expected on my machine.  As I said, this is a straight DOS environment.  'setlocal' returns a "Bad command or filename" error.
Elena

Which version of MS-DOS are you using?

You can find that out using VER at the command line.
ASKER CERTIFIED SOLUTION
Avatar of NVIT
NVIT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Solutions given.