Batch Script - Replace a String
Advertisements
To replace a substring with another string use the string substitution feature.
Example
@echo off set str=This message needs changed. echo %str% set str=%str:needs=has% echo %str%
The key thing to note about the above program is, the example replaces the word ‘needs’ with the string ‘has’ via the statement %str:needs = has%
Output
The above command produces the following output.
This message needs changed. This message has changed.
batch_script_strings.htm
Advertisements