简体   繁体   中英

string manipulation command line windows 7

i have this script which i think should work, what i actually want is to remove the quotes at either end of the version number

echo  parsed in %1 %2
IF "%1%" == "BUILD_VERSION" (
    echo %2:~1,12%)

the results are:

S:\Office\Source\Framework\Code>echo  parsed in BUILD_VERSION "13.000.0000"
 parsed in BUILD_VERSION "13.000.0000"

S:\Office\Source\Framework\Code>IF "BUILD_VERSION" == "BUILD_VERSION" (echo "13.
000.0000":~1,12 )
"13.000.0000":~1,12

all the string functions I have tried do the same. i got my example to crib from here (which I have only just realised isn't stackoverflow) https://superuser.com/questions/228794/how-to-extract-part-of-a-string-in-windows-batch-file

Referencing the value of a parameter always without double quotes independent on parameter was passed to batch file with or without double quotes is possible with ~ between % and the parameter number as Stephan wrote in first comment.

@echo parsed in %~1 %~2

This single line in batch file called with BUILD_VERSION "13.000.0000" results in the output

parsed in BUILD_VERSION 13.000.0000

Help of command FOR output in a command prompt window after entering either for /? or help for contains the explanation for this replacement and others on referencing either a parameter of a batch file or a variable of command FOR .

See help of command SET displayed on entering set /? or help set in a command prompt window to get explained what can be used for modifying the value of an environment variable. But those modifiers cannot be used on batch parameters or variables of command FOR as Stephan wrote in his second comment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM