Link to home
Start Free TrialLog in
Avatar of AlexKhaw
AlexKhaw

asked on

How to truncate a string from one range to another range in DOS batch

Hi there,
I am trying a simple thing, i wish to truncate a string, for example:
Set name=123456789

i want to truncate the above string to:
Set name=12345678, just remove the last character? I have no idea how to start, because it is limited to Dos batch for me in the execte environment, anyone can help?
Thank you  very much
Avatar of KelvinY
KelvinY

Hi Alex

I'm not sure from you statement exactly how restricted you are within the DOS environment. If you don't mind I'd like to put a few questions to clarify your situation.

1) Which version of DOS are you using?
2) Where does your input "Set name=123456789" come from? Is this text typed at the command prompt, or is text within a file?
3) Are you restricted to only using DOS commands to handle your string, or can you create something like a VBS file? If you're restricted to DOS only I don't think it can be done. If you can create VBS files the problem is simple.

Regards
  Kelvin
ASKER CERTIFIED SOLUTION
Avatar of JesterToo
JesterToo
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
>  I have no idea how to start, because it is limited to Dos

Then you should ask Q in DOS TA, which is not a programming language even in the general sense.
In programming you can deal with string lengths or use left or right side, etc. Each language may be different in how that is done, but as a standalone, DOS is an OS, not a language

If you have more than dos, such as XP, then alternatives like vbs may be available if enabled
Based on other questions Alex has asked (regarding XP and Perl), it appears that he used the term "DOS" to actually mean "command shell".  And, while I'll certainly agree that the command shell scripting capabilities of Windows don't constitute a very robust "language" there are some people that can do amazing things with it... it's just not very intuitive!

The script I provided above accomplishes what was asked.  The next-to-last line actually does all the work... the other lines just setup the problem and display the before/after values to demonstrate that it works.

As for MSDOS being an OS... I think that's being pretty charitable!  I'd consider it more of a "control program" than an Operating System.  It was hardly more advanced than CP/M which preceeded it.

Regards,
Lynn