Andenrx
Andenrx

Reputation: 616

Batch only use first letter

Basically I want some way to make a code that is like this
set /p type= then
if %type% ==b
if %type% ==B
if %type% ==Ba
if %type% ==ba
if %type% ==ban
if %type% ==bana
... up until
if %type% ==banana
if %type% ==Banana

or something like that. So is there a short cut or do I just need to say
if %type% ==b or B
or make them type the whole word out.

If there is a way to do something like they type hhhhhhhhhh,help,h,hello,hi, or anything that starts with an "h" it would act the same. That way I can do basically the same thing as up above.

Sorry, I wasn't really sure how to word this. Also it seems like the type of thing that might not exist.

Upvotes: 0

Views: 420

Answers (1)

SachaDee
SachaDee

Reputation: 9545

Maybe something like this can help.

@echo off

set $TestChar=h

set /p "$type=Enter your string : "

if /i "%$type:~0,1%"=="%$TestChar%" (echo First Char of %$type% is %$Testchar%
                                     exit /b)
echo First Char of %$type% is not %$Testchar%
pause > nul

Upvotes: 2

Related Questions