Solved Detect additional text input.

April 9, 2012 at 00:34:38
Specs: Windows 7 Pro, Intel(R) Core(TM) i3 / 3.20 GHz / 8 GB Ram
Is it possible to take user input and read text after a space?

set /p input=Light On

So detecting what the second word is, if it is nothing, Yes or No.

Any help would be appreciated.


See More: Detect additional text input.

Report •


#1
April 9, 2012 at 03:04:16
@echo off

set input=
set /P input=Enter TWO words^>
for /F "tokens=2" %%a in ("%input%") do goto :YES

echo. the user entered just ONE or NO word.
exit /B

:YES
echo. The user entered "%input%"


Report •

#2
April 9, 2012 at 22:26:22
Not entirely sure about that "for" command.
(I don't understand that command very much.)

I tried it and there is one thing missing.
It shall not output everything at once, but output the first word in %w1% and the second word in %w2%.


Report •

#3
April 10, 2012 at 07:43:15
✔ Best Answer
The following slightly modified script parses user's input setting word1 as the first word entered and the remainder after first space as word2. FOR /F is the NT batch statement aimed to parse commands output and variables content. Its syntax is quite complex and beyond a short note or quick sample. To get a quick while not friendly help at prompt type for /?

@echo off

set input=
set /P input=Enter TWO words^>

for /F "tokens=1*" %%a in ("%input%") do if "%%b"=="" (
goto :NO
) else (
set word1=%%a
set word2=%%b
goto :YES
)

:NO
echo. the user entered just ONE or NO word.
exit /B

:YES
echo. The user entered "%word1%" and "%word2%"


Report •

Related Solutions

#4
April 11, 2012 at 04:35:22
I am curious about those "tokens" in the for, but else it worked like a dream. :D

Thank you for helping me, I can finaly (I think so...) make my program done!


Report •


Ask Question