Computing Staff
  • 0

Batch Spaces In Input

  • 0

Batch Spaces in Input??
Help! does anyone know how to make it possible to add spaces in input?
for example

echo oh no a troll appeared!
set /p input=
if /i %input%==hit troll with axe goto GAMEOVER

if i type “hit troll with axe” it doesnt work!, how do i make it posible to add spaces?
also the “If NOT defined” command doesnt work for me what am i doing wrong?
i typed in

:cave
echo Oh no a Troll!!
set /p input=
if /i %input%==hit troll with axe goto GAMEMOVER
if not defined input (
echo invalid
pause
goto cave
)
but it wont work!, it just skips to the next part, help please!
i hope i explained clearly, thanks for any feedback

Share

1 Answer

  1. two things i noticed. whenever you use “set /p”, you should clear the variable imm. before the set, otherwise it will retain any prior content, and not be “” if the user hits a null-entry. Second, you probably need quotes around the var when testing since it may contain spaces. Here’s the gist:
    set input =
    set /p input=
    if /i “%input%”==”hit troll with axe” goto GAMEMOVER

    • 0