Page 1 of 1

How Can I use the variables properly.. ??

Posted: 30 Nov 2006 01:31
by mhmanio
hi.. can anyone help me on how to properly use the variable during substring.

here's the scenario..

when i run this script:

set orig_str=E1METRODRUG001MDIAUTOTESTFILE.TXT
set max=100
set strlen=21
echo strlen :: %strlen%
echo %orig_str%
set new_str=%orig_str:~21,100%
echo.%new_str%

the Output is: TESTFILE.TXT, which is correct.

but when i try to susbtitute the variable "strlen" and "max" to 21 and 100 i got an output, "E1METRODRUG001MDIAUTOTESTFILE.TXTstrlenmax%"

the script after substitution:

set orig_str=E1METRODRUG001MDIAUTOTESTFILE.TXT
set max=100
set strlen=21
echo.%orig_str%
set new_str=%orig_str:~%strlen%,%max%%
echo.%new_str%


..
What i want is to use variables so that i can pass values to the variable whenever i call the script.

it should look like this..

set orig_str=E1METRODRUG001MDIAUTOTESTFILE.TXT
set max=%1
set strlen=%2
echo.%orig_str%
set new_str=%orig_str:~%strlen%,%max%%
echo.%new_str%

hope u guyz can help me..

Posted: 30 Nov 2006 20:43
by DosItHelp
mhmanio,

Try this:

Code: Select all

set orig_str=E1METRODRUG001MDIAUTOTESTFILE.TXT
set max=100
set strlen=21
echo.%orig_str%
call set new_str=%%orig_str:~%strlen%,%max%%%
echo.%new_str%


DOS IT HELP? :wink:

^^

Posted: 04 Dec 2006 19:45
by mhmanio
yes, thanks! this greatly solve my problem..