Computing.Net > Forums > Programming > Advanced Batch Files

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.

Advanced Batch Files

Reply to Message Icon

Name: MikeKozar
Date: June 1, 2009 at 17:50:25 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

I'm trying to get a batch file to remove
%SUBSET% from %VARIABLE%, and let me
use the remainder as %RESULT%. However,
I can't seem to get the SET command to parse
a nested string;

SET RESULT=%VARIABLE:%SUBSET%=%

...for instance, sets %RESULT% equal to
SUBSET...not the value of the variable
%SUBSET%, but the string SUBSET.

Replacing the % symbols with ! symbols gives
the same result.

I've been able to work around this by using
ECHO to build a second, temporary batch file
where %SUBSET% is rendered as a literal
string, and reading the output of that batch file
into a temporary text file and back into the
calling batch file, but that's pretty roundabout.

Anybody know how to do a simple string
replace with two variables? I'm on XP.



Sponsored Link
Ads by Google

Response Number 1
Name: reno
Date: June 1, 2009 at 22:08:18 Pacific
Reply:

add a call in front of the statement

call SET RESULT=%%VARIABLE:%SUBSET%=%%


0

Response Number 2
Name: IVO
Date: June 2, 2009 at 02:21:34 Pacific
Reply:

setlocal EnableDelayedExpansion
set RESULT=!VARIABLE:%SUBSET%=!

When using variable of variable the ! must mark the outer one.

0

Response Number 3
Name: MikeKozar
Date: June 2, 2009 at 12:24:37 Pacific
Reply:

Thanks, guys!

I tested both solutions, and they both do exactly what I
needed. You guys just made my script %20 faster - great
work.

~Mike


0

Sponsored Link
Ads by Google
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: Advanced Batch Files

advanced batch file help needed www.computing.net/answers/programming/advanced-batch-file-help-needed/8803.html

Advanced bat file for copying files www.computing.net/answers/programming/advanced-bat-file-for-copying-files/17021.html

Batch File Formmatting Help, Please www.computing.net/answers/programming/batch-file-formmatting-help-please/14040.html