Home > Net >  All letters, numbers and symbols in one?
All letters, numbers and symbols in one?

Time:01-30

Hey does anyone know if there is a command or something that allows me to have all the letters, numbers and characters in one?

:start
set input=
set /p input=[Y / N]? 
if %input%==Y goto y
if %input%==N goto n
if %input%==* goto this

:y
goto end

:n
exit

:this
@echo.   Only J or N

:end

Here you can already see that I tried to get everything in one with "*" which unfortunately didn't work...

Thank you for trying to help me but I would like to point out again that I need help to find something that allows me to use all the characters, letters and symbols in one. example:

if I take y then he goes on. if I take n then it closes. and when i use g or h he says: "can't do, just y and n (for yes and no)"

but things like "*" or "%word%" don't work and yes, I have "choice /?" Already tried but when I do it like this it doesn't work either:

for %%i in (
D o " you " k n o w " to " h e l p " me
) do (<nul set /p "=.%bs%%%~i" & >nul ping -n 1 localhost)
@ echo ?

CHOICE

[I don't care about syntax errors or something. if it works then it fits, it's just this one thing to use all characters, letters and symbols in one.] No hate <3

CodePudding user response:

if has no wildcard, but as I already commented, you don't need the third if at all. If Y and N are already handled, it can only be "anything else"

:start
set "input="
set /p "input=[Y / N]? "
if "%input%"=="Y" goto y
if "%input%"=="N" goto n
echo it's Y or N, nothing else&goto :start

The quotes makes it a little bit safer, but note this still isn't safe at all.

Cmd handles several characters (so called "poison chars" like <>|&"!) different (and even more under certain conditions).
A more secure method:

@echo off
setlocal enabledelayedexpansion
:loop
set "input="
set /p "input="
>nul 2>&1 (
echo/!input!|findstr /x "Y" >nul && goto YES
echo/!input!|findstr /x "N" >nul && goto NO
)
echo FAIL
goto :loop
:YES
echo yeah
goto :eof
:NO
echo nope
goto :eof

(Disclaimer: I'm quite sure, someone will find an input-string to make it fail too)

Note: both if and findstr support the /i switch to make them case-insensitive.

CodePudding user response:

And just for the sake of showing everyone else how to perform this task using the appropriate commands:

%SystemRoot%\System32\choice.exe
If ErrorLevel 2 Exit /B
Rem The code you had under :end replaces this line
  •  Tags:  
  • Related