I am trying to make a chatbot.
This is my script:
:start
set /p message=
if %message%==Hello echo Hi!
goto start
But if I try to type something in like.. hello = world
, it closes. How do I prevent that?
I am trying to make a chatbot.
This is my script:
:start
set /p message=
if %message%==Hello echo Hi!
goto start
But if I try to type something in like.. hello = world
, it closes. How do I prevent that?
if /i "%message%"=="Hello world" echo Hi!
Quote both sides of the comparison-operator. Note that /i
makes the test case-insensitive.
If you want to test if the message starts with hello
then test %message:~0,5%
@echo off
:start
cls
set /p "message=type something: "
if /i "%message:~0,5%"=="Hello" echo Hi!
goto start
So by typing hello world
it will detect the characters 0 - 5 being hello
, /i
makes it case insensitive as mentioned by @magoo
Your question has already been answered succinctly by Magoo, this is just an example to show a way of detecting if the input string contained the case insensitive string hello
:
If /I Not "%message%"=="%message:hello=%" Echo Hi!