# Solved: "string substitution" in dos batch



## jglong3 (Jul 23, 2003)

Hello,,,,  

Thanks for your time, help, and advice!!!!

Using Windows 98 SE.

There are many examples found related to dos batch command file logic 
to replace characters within a string. The examples found on the Internet show how to deal with strings that contain spaces and removing spaces. Also, how to replace a specific character with another character.

The example below was taken from:

www.dostips.com

EXAMPLE
Description
This script snippet can be used to remove all spaces from a string.

Code:
set str= word &rem
echo."%str%"
set str=%str: =%
echo."%str%"

Output: " word "
"word"

It appears that the command line version for W98 SE does not handle 
the "string substitution" syntax or I am not using the example correctly.
The example code above was placed as is in a .bat file and executed. 
The output for the example shows the expected result from " word " is "word". But, the entire string was removed to only "".

Can anyone help?

THANKS for your time, help, and advise!!!!

Jerry


----------



## Squashman (Apr 4, 2003)

Works fine on XP. I don't have a 98 box to test it on.

I have such a hard time figuring stuff out in Dos Batch files because I learned most of my initial scripting in Unix. Most of the unix utilities have been ported to Windows, which cuts down on my scripting time in DOS.

One simple command will do what those 4 lines of code does.
tr which is short for translate.

tr -d " "

You can download them from here. I just wish I had a case statement.
http://unxutils.sourceforge.net/


----------



## jglong3 (Jul 23, 2003)

Hello Squashman,,,,  

Thanks for the REPLY!!!!

Later that day I finally found a document that described the suspicion about "string substitution" syntax and this is not available on W98,,,Seems only on OP SYS's newer than 98.

Also,,,,,the answer to the situation was eventually found. An example was found on the INTERNET at www.robvanderwoude.com The example shows the replacement of any character in a string using the CHOICE command output to a BAT file. This file in turn is called and it returns each character in the string as a seperate %1, %2,%3,,,,,%i argument. In 98 this allows each character in the sting to be examined, discarded with SHIFT and/or replaced as required.

This situation is resolved!!!!!

Thanks for your time, help, and advice!!!!  

Jerry


----------



## JohnWill (Oct 19, 2002)

*You can mark your own threads solved using the thread tools at the top of the page in the upper right corner.©*


----------



## Squashman (Apr 4, 2003)

Well, here is one example where Unix Scripting is so much easier then Batch Files.


----------



## jglong3 (Jul 23, 2003)

Hello JohnWill,,,,  

OK THANKS,,,,I had never known that and I was just about to ask if it could be done by a MEMBER,,,,,,


THANKS!!!!!!!!

Jerry


----------



## jglong3 (Jul 23, 2003)

Hello Squashman,,,,  


YEP!!! AND it is great that these UNIX Job Control commands are available on Windows OP SYS.


THANKS AGAIN!!!!  

Jerry


----------

