gpt4 book ai didi

batch-file - 通过批处理文件检查输入

转载 作者:行者123 更新时间:2023-12-04 00:36:20 25 4
gpt4 key购买 nike

我正在做用户输入并检查他们是否输入了 ny...但它不起作用,因为它说两种方式。

这是我所拥有的:

@echo off
set /P theuserinput="Type your name: "
echo So your name is: %theuserinput%?
set /P isit="Y/N: "
echo You typed: %isit%
if (%isit% == "y") goto :saidyes
if (%isit% == "n") goto :saidno

:saidyes
echo Hooray!

:saidno
echo Aww
PAUSE

最佳答案

首先你可以在两个 if 之后添加一个默认的 goto。

然后,在这两个测试中,您必须在 %isit% 周围添加引号并删除括号。您还可以添加/I 标志来进行不敏感的字符串比较。

最后,在每个回声后添加 goto 以跳过下一个。

@echo off
set /P theuserinput="Type your name: "
echo So your name is: %theuserinput%?
set /P isit="Y/N: "
echo You typed: %isit%
if /I "%isit%" == "Y" goto :saidyes
if /I "%isit%" == "N" goto :saidno
goto :error

:saidyes
echo Hooray!
goto :end

:saidno
echo Aww
goto :end

:error
echo ERROR

:end
PAUSE

关于batch-file - 通过批处理文件检查输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5666410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com