map and lookup - please explain
Posted: 25 May 2008 08:12
Can someone explain the example on the 'map and lookup' tips under the 'String manipulation'? http://www.dostips.com/DtTipsStringMani ... _MapLookup
REM ---- Example 2: Translate abbreviation into full string ----
SET v=sun
set map=mon-Monday;tue-Tuesday;wed-Wednesday;thu-Thursday;fri-Friday;sat-Saturday;sun-Sunday
CALL SET v=%%map:*%v%-=%%
SET v=%v:;=&rem.%
ECHO.%v%
I know it works in a script but I failed to make it work line by line on the command prompt(after account for the difference of %% in script vs command line). I know the 'CALL' line is to replace string up to the key value by null and the following line is to replace everything starting from ; to the end by null.
Bu what is the reason for 'CALL'? What will be different if withou using CALL? Why '&rem.'? Primarily, I would like to know how I can use those constructs in other scenario.
Maybe someone has already know about this, for the purpose those 2 examples want to achieve, I have the following code snipet that can do the same(but it can not exactly achieve the goal of 'map and lookup' since the key need to be numeric and in sequence). But I think this is simpler:
set v=05
set Months=Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec
for /f "delims=; tokens=%v%" %%i in ("%Months%") do @echo %%i
-Frank
REM ---- Example 2: Translate abbreviation into full string ----
SET v=sun
set map=mon-Monday;tue-Tuesday;wed-Wednesday;thu-Thursday;fri-Friday;sat-Saturday;sun-Sunday
CALL SET v=%%map:*%v%-=%%
SET v=%v:;=&rem.%
ECHO.%v%
I know it works in a script but I failed to make it work line by line on the command prompt(after account for the difference of %% in script vs command line). I know the 'CALL' line is to replace string up to the key value by null and the following line is to replace everything starting from ; to the end by null.
Bu what is the reason for 'CALL'? What will be different if withou using CALL? Why '&rem.'? Primarily, I would like to know how I can use those constructs in other scenario.
Maybe someone has already know about this, for the purpose those 2 examples want to achieve, I have the following code snipet that can do the same(but it can not exactly achieve the goal of 'map and lookup' since the key need to be numeric and in sequence). But I think this is simpler:
set v=05
set Months=Jan;Feb;Mar;Apr;May;Jun;Jul;Aug;Sep;Oct;Nov;Dec
for /f "delims=; tokens=%v%" %%i in ("%Months%") do @echo %%i
-Frank