No problem. You can use the "set" command in two different ways to read in your variables and then perform an action on them.
=== First,
you can read in the individual numbers by using the substring function of 'set'. For example, if your initial variable is called 'var', then we can use this command,
set var1=%var:~2,1%
to start at the 3rd character (offset 2, or ~2) and read in 1 character. If your var=ws123456, then this command would set var1=1, the 3rd character in the string.
===Second
You can use the "/a" switch of 'set' to evaluate numeric expressions, like add, subtract, multiply, divide, etc. You can do this with actual numbers, or with previously defined environment variables.
For example, if we used the first command to populate var1=1 and var2=2, then we can use this command,
set /a sum1=%var1%+%var2%
to populate "sum1" with the value 3.
===========
Here's my test.bat file example to illustrate. I've added a little check for the variable and a syntax section, too.
@echo off
rem if the variable is not entered, then display the syntax
if "%1"=="" goto :SYNTAX
rem get the variable for use in this batch
set var=%1
@echo on
set var1=%var:~2,1%
set var2=%var:~3,1%
set var3=%var:~4,1%
set var4=%var:~5,1%
set var5=%var:~6,1%
set var6=%var:~7,1%
set /a sum1=%var1%+%var2%
set /a sum2=%var3%+%var4%
set /a sum3=%var5%+%var6%
set newvar=%sum1%%sum2%%sum3%
@echo off
GOTO :EOF
:SYNTAX
echo.
echo You're missing a variable
echo.
echo Syntax:
echo test.bat 'variable'
echo.
echo Example:
echo test.bat ws123456
echo.
======================
Here's the output of the batch file, which I ran in my c:\temp directory. If you don't want this displayed when the batch runs, then just remove the '@echo on' that I have in my example.
C:\temp>test ws123456
C:\temp>set var1=1
C:\temp>set var2=2
C:\temp>set var3=3
C:\temp>set var4=4
C:\temp>set var5=5
C:\temp>set var6=6
C:\temp>set /a sum1=1+2
C:\temp>set /a sum2=3+4
C:\temp>set /a sum3=5+6
C:\temp>set newvar=3711
===Caveats,
This batch file works from the information that the variable was is in a particular format with a certain length of numbers.. So it only works if the variable numbers start at the 3rd position and that there are 6 numbers.
If the numbers of your variable start at a different place, then you can modify the offset value in the substring section to pick them up.
If you have less than 6 characters, then this batch will display some errors because it assumes 6 characters, so you will get "missing operand" errors in the sum section.
It would be possible to work from the end of the variable string and read in the individual numbers backwards, then determine how many were read in, then do the summing, but that would take a bit more work.
2007-05-28 00:40:37
·
answer #1
·
answered by Kevin 7
·
6⤊
0⤋
Do you mean you want to concatenate a series of numbers?
That is not the same thing as adding a series of numbers.
Or do you mean both. You want to add pairs of numbers and then concatenate the sum of the pairs?
Please clarify.
2007-05-25 00:52:48
·
answer #3
·
answered by Anonymous
·
1⤊
0⤋
yep - a free one Acid Express or vegas pro sonic foundry makes them I think do a google search for Acid Express then copy the two mp3 on separate tracks - you will have 8 tracks to add songs to
2016-03-19 01:06:25
·
answer #4
·
answered by Anonymous
·
0⤊
0⤋