Computing.Net > Forums > Programming > Batch string substitution

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch string substitution

Reply to Message Icon

Name: RAJ
Date: February 2, 2005 at 13:12:12 Pacific
OS: Win 2K
CPU/Ram: Pentium4 / 512M
Comment:

I have a question with regards to variable substring substitution in an NT batch program.

For example, the following piece of code works as expected and replaces 'ab' with 'xy'.

::Edit and replace the character string 'ab' with 'xy'
SET v_test=123abcd
Set v_replacement=xy
SET v_result=%v_test:ab=xy%
ECHO %v_result% = 123xycd

How can I perform the substitution, when the replacement string is a variable instead of the contant string 'xy'
i.e. I want to replace 'ab' with the contents of the variable %v_replacement%, instead of the hardcoded value 'xy' ?

Thanks.



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: February 2, 2005 at 14:00:25 Pacific
Reply:

The command prompt as to be executed with
ENABLEDELAYEDEXPANSION for the code below
to work.
1, Right click the "Command Prompt" as add
the "/v" in the Target box as below.
and run the code.

%SystemRoot%\system32\cmd.exe /v

Tested with WinXP Pro.

@echo off
SET v_test=123abcd
Set v_replacement=xy
SET v_result=%v_test:ab=!v_replacement!%
ECHO %v_result%=123xycd


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch string substitution

batch merge/substitute tokens www.computing.net/answers/programming/batch-mergesubstitute-tokens-/16322.html

Batch command string substitution www.computing.net/answers/programming/batch-command-string-substitution/18209.html

please check me this batch www.computing.net/answers/programming/please-check-me-this-batch/19349.html