标题: 请教 set 变量输入空格后的判断问题
[打印本页]
作者: kingshui
时间: 2007-1-6 00:59
标题: 请教 set 变量输入空格后的判断问题
如下:
set choice=
set /p choice= 唔该擒入选项号:
if {%choice%}=={} goto err
if /i %choice%==01 goto game
if /i %choice%==02 goto junk
if /i %choice%==03 goto updata
if /i %choice%==04 goto found
if /i %choice%==05 goto fix
if /i %choice%==06 goto find
if /i %choice%==07 goto replace
if /i %choice%==08 goto copy
if /i %choice%==09 goto del
if /i %choice%==10 goto nomal
if /i %choice%==0 exit
现象是:
输入指定以外的字符时
自动退出了批处理
本来不应该是跳转到 err标签的吗?
[
Last edited by kingshui on 2007-1-6 at 02:00 AM ]
作者: NaturalJ0
时间: 2007-1-6 01:04
你写的代码中,输入为空时跳到ERR,代码没有指定其它情况可以跳到ERR。你可以在最后加一句跳到ERR,因为上面全不满足,才可能执行到它。
作者: kingshui
时间: 2007-1-6 01:09
呵呵...
谢谢指教...
刚才自己又重新的完整看了一遍自己的代码..
结果就得出你说的结论了...
以前没注意到这个问题...
呵呵...
作者: kingshui
时间: 2007-1-6 01:40
另外..
想请问一下...
如果输入的是空格应该怎么判断呢?
作者: lxmxn
时间: 2007-1-6 01:51
if {%choice%}=={ } goto error
作者: kingshui
时间: 2007-1-6 01:58
Quote: |
Originally posted by lxmxn at 2007-1-6 01:51 AM:
if {%choice%}=={ } goto error |
|
不知道怎么回事..
用以上的语句也不行
能不能过滤掉空格呢??并不是指仅一个空格..是指所有的空格
以下是我的源代码:
@echo off
:nomal
echo 01.game
echo 02.junk
echo 03.updata
echo 04.found
echo 05.fix
echo 06.find
echo 07.replace
echo 08.copy
echo 09.del
echo 10.nomal
set choice=
set /p choice= 唔该擒入选项号:
if {%choice%}=={} goto err
if {%choice%}=={ } goto err
if /i %choice%==01 goto game
if /i %choice%==02 goto junk
if /i %choice%==03 goto updata
if /i %choice%==04 goto found
if /i %choice%==05 goto fix
if /i %choice%==06 goto find
if /i %choice%==07 goto replace
if /i %choice%==08 goto copy
if /i %choice%==09 goto del
if /i %choice%==10 goto nomal
if /i %choice%==0 exit
:err
echo err
pause
goto nomal
:game
echo game
pause
goto nomal
:junk
echo junk
pause
goto nomal
:updata
echo updata
goto nomal
pause
goto nomal
:found
echo found
pause
goto nomal
:fix
echo fix
pause
goto nomal
:find
echo find
pause
goto nomal
:replace
echo replace
pause
goto nomal
:copy
echo copy
pause
goto nomal
:del
echo del
pause
goto nomal
[
Last edited by kingshui on 2007-1-6 at 02:04 AM ]
作者: lxmxn
时间: 2007-1-6 02:58
现在你输入0 1 和输入01的效果是一样的,都显示game。
@echo off
:nomal
echo 01.game
echo 02.junk
echo 03.updata
echo 04.found
echo 05.fix
echo 06.find
echo 07.replace
echo 08.copy
echo 09.del
echo 10.nomal
set choice=
set /p choice= 唔该擒入选项号:
set choice=%choice: =%
if {%choice%}=={} goto err
if /i %choice%==01 goto game
if /i %choice%==02 goto junk
if /i %choice%==03 goto updata
if /i %choice%==04 goto found
if /i %choice%==05 goto fix
if /i %choice%==06 goto find
if /i %choice%==07 goto replace
if /i %choice%==08 goto copy
if /i %choice%==09 goto del
if /i %choice%==10 goto nomal
if /i %choice%==0 exit
:err
echo err
pause
goto nomal
:game
echo game
pause
goto nomal
:junk
echo junk
pause
goto nomal
:updata
echo updata
goto nomal
pause
goto nomal
:found
echo found
pause
goto nomal
:fix
echo fix
pause
goto nomal
:find
echo find
pause
goto nomal
:replace
echo replace
pause
goto nomal
:copy
echo copy
pause
goto nomal
:del
echo del
pause
goto nomal
作者: kingshui
时间: 2007-1-6 03:02
非常感谢....
刚才在看
http://www.cn-dos.net/forum/view ... ghlight=&page=1篇文章..
一下子还没有反应过来...
[
Last edited by kingshui on 2007-1-6 at 03:03 AM ]