How Can I use the variables properly.. ??

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mhmanio
Posts: 4
Joined: 06 Nov 2006 02:42

How Can I use the variables properly.. ??

#1 Post by mhmanio » 30 Nov 2006 01:31

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..

DosItHelp
Expert
Posts: 239
Joined: 18 Feb 2006 19:54

#2 Post by DosItHelp » 30 Nov 2006 20:43

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:

mhmanio
Posts: 4
Joined: 06 Nov 2006 02:42

^^

#3 Post by mhmanio » 04 Dec 2006 19:45

yes, thanks! this greatly solve my problem..

Post Reply