Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi
I'm trying to figure out if I can insert varables into of a set command.
No luck so far.ie..
set Days=SunMonTueWedThuFriSat
set Pos=3
set WDay=%Days:~%Pos%,3%
echo %WDay%
rem should echo Mon

Like this?
@ECHO OFF
SET DAYS=ECHO. | DATE | FIND /I "Current"
ECHO %DAYS%
Quoth the raven, `Nevermore.'rp$D

Yes, you can do it just enabling the delayed expansion of variables. That way you can "index" an array type environment variable like the one you posted.
Pay attention to mark with ! the outer variable to be indexed as in your rearranged code@Echo Off
SetLocal EnableDelayedExpansionSet Days=SunMonTueWedThuFriSat
Set Pos=3
Set WDay=!Days:~%Pos%,3!
Echo %WDay%EndLocal
Rem should echo MonThe sample should be self explanatory, but I'm at your side if you need any support.
Good scripting
IVO

Hi
Works great thanks IVO for your time and knowledge.
I Tryed Delayed Expansion and put the ! symbols
arount the !Pos! variabled, never throught about putting them around the whole statememt.
Much Appreciated.
Harry

Hi IVO,
Thanks; that helps with something else I'm working on.
d10,
I guess I should be flattered to be mentioned in the same breath with IVO.
:0)
If at first you don't succeed, you're about average.M2

Hi
I've learned alot from both of yours and IVO coding.
Programmers can learn alot from studying other people's coding.
It's not easy, but there no right or wrong way to write a program, maybe that's why they call it a art.
Give 3 programmers some code to write and there all do if differently.
Many Thanks to you both and Others.

Hi dtech10,
I agree, programming is "science art" (much like Sci-Fi), a discipline where heart and mind get togheter as Pascal could say.
There are strong coding principles that have to be taken in account as structured and object oriented programming, but if you don't feel the underlying flavour you miss the right solution.
Thanks again for your (M2's too) kind words.
IVO from Milano, Italy

d10,
I saw a book on programming called "Nailing Jelly to a Tree".
That pretty much sums it up.
If at first you don't succeed, you're about average.M2

![]() |
C++ How to save calculate...
|
Launch secure process
|

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