【发布时间】:2014-11-10 18:58:40
【问题描述】:
所以我编写了一个批处理脚本,它可以帮助组织我在游戏中运行的一个小彩票。 它要求用户输入玩家姓名,然后要求输入 1-100 的最多 5 个彩票号码。 该脚本将玩家姓名和他们选择的号码添加到文本文档中,并将这些号码添加到文本文档中,以便它知道哪些号码已经“被占用”,如果我尝试输入重复(还进行了一些排序,以便“按顺序”显示“采用”的数字,以便于查看)。
当我使用“findstr /c:”查看“获取的数字”文件时,如果我查找“1”,它会假设 1、10、100 等是相同的数字,因为...这些数字有我在他们身上寻找什么。我通过输入单个数字 01-09 解决了这个问题,但这仍然让我留下“10”和 100(在 findstr 眼中)相同。
所以我尝试使用“findstr /x /c:”来获得确切的值,这就是我遇到问题的地方。现在 /x 在那里,它只是忽略检查值是否相同,我不明白为什么,请帮助:P 它让我发疯。
@echo off
echo --------------------
echo Lottery Program
echo --------------------
echo.
echo.
echo These are the Taken numbers.
type takennumbersnice.txt
echo.
echo.
set /p name= Please type the players name
:thestart
echo ---------------------------
set /p multinum1= Please type their first number [01-100]
findstr /x /c:%multinum1% takennumbersnice.txt && (
echo This number has already been taken! & pause && goto thestart
) || (
echo %multinum1%>> takennumbers.txt & goto next)
:next
:thestart2
echo ---------------------------
set /p multinum2= Now type their second number [0 if they only picked 1 number]
if '%multinum2%'=='0' (
goto endofnums
) else (
goto 3
)
:3
findstr /x /c:%multinum2% takennumbersnice.txt && (
echo This number has already been taken! & pause && goto thestart2
) || (
echo %multinum2%>> takennumbers.txt &goto next2)
:next2
:thestart3
echo ---------------------------
set /p multinum3= Now type their third number [0 if they only picked 2 numbers]
if '%multinum3%'=='0' (
goto endofnums
) else (
goto 4
)
:4
findstr /x /c:%multinum3% takennumbersnice.txt && (
echo This number has already been taken! & pause && goto thestart3
) || (
echo %multinum3%>> takennumbers.txt &goto next3)
:next3
:thestart4
echo ---------------------------
set /p multinum4= Now type their fourth number [0 if they only picked 3 numbers]
if '%multinum4%'=='0' (
goto endofnums
) else (
goto 5
)
:5
findstr /x /c:%multinum4% takennumbersnice.txt && (
echo This number has already been taken! & pause && goto thestart4
) || (
echo %multinum4%>> takennumbers.txt &goto next4)
:next4
:thestart5
echo ---------------------------
set /p multinum5= Now type their fifth number [0 if they only picked 4 numbers]
if '%multinum5%'=='0' (
goto endofnums
) else (
goto 6
)
:6
echo ---------------------------
findstr /x /c:%multinum5% takennumbersnice.txt && (
echo This number has already been taken! & pause && goto thestart5
) || (
echo %multinum5%>> takennumbers.txt)
:endofnums
set number= %multinum1% %multinum2% %multinum3% %multinum4% %multinum5%
echo %name% has chosen the number[s] %number%
echo %name% %number% >> lottery.txt
sort < takennumbers.txt > takennumbersnice.txt
echo press any key to exit
pause > nul
exit
【问题讨论】:
标签: batch-file findstr