Having set /p ignore capital letters in batch


Is there any way (via tag or other wise) to have Set /p ignore capital letters in a batch script?


I don't know about ignore, but you could convert them to lower case.

Set /P Text=Please type something: Set Text=%Text:A=a% Set Text=%Text:B=b% Set Text=%Text:C=c% ... Echo %Text%

If you wanted to use a For command to convert to lower case:

Set Text /P=Please type something: For %%i In ("A=a" "B=b" "C=c" ...) Do Call Set "Text=%%Text:%%~i%%" Echo %Text%

Or replace "A=a" with "A=", etc. to remove capitals.


Alternatively, and depending on what you plan to do with the user input, if you want to use it in a decission, then you may use the /I switch of the IF command. See HELP IF.

Set /P TEXT=Choose an option: IF /I %TEXT%==A ( echo DOA ) ELSE ( IF /I %TEXT%==B ( echo DOB ) ELSE ( IF /I %TEXT%==C ( echo DOC ) ELSE ( echo DONOTHING )))


Upper To Lower Case:

@echo off :main cls set str= set /p str= input(Press enter to exit): if not defined str exit cls echo. echo Before:"%str%" for %%i in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do call set str=%%str:%%i=%%i%% echo ____________________________________________ echo. echo After:"%str%" echo. echo Press Any Key To Convert again pause>nul goto main


All input limitations of set /P command, including this one, may be solved if we write our own readline routine. This is the basic version:

@echo off rem Insert next line if needed: SETLOCAL DISABLEDELAYEDEXPANSION set exclam=! set caret=^^ setlocal EnableDelayedExpansion set ascii=01234567890123456789012345678901^ !exclam!^"#$%%^&'()*+,-./0123456789:;^<=^>?^ @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]!caret!^_^ `abcdefghijklmnopqrstuvwxyz{^|}~ for /F %%a in ('echo prompt $H ^| cmd') do set BS=%%a set lineread= :nextkey getakey set code=%errorlevel% if %code% lss 32 goto checkBS :ascii set char=!ascii:~%code%,1! colormsg 7 "!char!" set lineread=!lineread!!char! goto nextkey :checkBS if not %code% == 8 goto checkExtended if "!lineread!" == "" goto nextkey colormsg 7 "%BS% %BS%" set lineread=!lineread:~0,-1! goto nextkey :checkExtended if not %code% == 0 goto checkCR getakey goto nextkey :checkCR if not %code% == 13 goto nextkey echo/ ECHO Line Read: [!lineread!]

For example, if you want to ignore capital letters on input just insert these two lines after :ascii label:

:ascii rem If key is between A (65) and Z (90): ignore it if %code% geq 65 if %code% leq 90 goto nextkey

To convert uppercase letters to lowercase ones:

:ascii rem If key is upcase (between A-65 and Z-90): convert it to lowcase (a-97 z-122) if %code% geq 65 if %code% leq 90 set /A code+=32

We may even write an asynchronous (concurrent) readline routine that allows the Batch file continue running at the same time it read the line.

Both GETAKEY.COM and COLORMSG.COM programs was previously given in this question: <a href="https://stackoverflow.com/questions/7923948/batch-color-per-line" rel="nofollow">Batch Color per line</a>


Rob's site to the rescue: here are some <a href="http://www.robvanderwoude.com/battech_convertcase.php" rel="nofollow">fleshed-out examples</a> of batch case conversion.


  • How would I send and receive packets over a WebSocket in Javascript
  • UIimage to char* conversion
  • Help translating Reflector deconstruction into compilable code
  • How to convert row to column in notepad++
  • Excel Date field value differs from c# dateTime by 1 day while reading excel file with EEPlus
  • Timing loops with asynchronous functions
  • Visualizing a large matrix in matlab
  • how do you obtain the address of an instance after overriding the __str__ method in python
  • Convert two columns Pandas data frame to dictionary of list with first column as keys
  • How to extract text from a PDF and decode characters?
  • C++ cout and enum representations
  • Java making confirming exit
  • EntLib Way to Bind “Null” Value to Parameter
  • is there a way to update filter with async data
  • DateTime.Today for a specific time zone
  • Magento get URL before current
  • Doctrine/Symfony entity generator and generating entity from one table
  • cordova is not defined - cordova.js has already been loaded :: Ionic
  • Casting between Interfaces and Classes
  • Ubuntu and bcrypt
  • jwtBearer bearer token with rc-1 update to ASP.Net 5
  • Enabling DTD support in Sql Server
  • Convert SQLite database to XML
  • Subclassing QGraphicsItem prevents me from being able to use itemAt() on a QGraphicsScene/View
  • WPF Visiblity Binding to Boolean Expression with multiple Variables
  • Conversion from string “a” to type 'Boolean' is not valid
  • Using JRuby with Rails 3.2
  • Code in Job's Script Block after Start-Process Does not Execute
  • Why Encoding.ASCII != ASCIIEncoding.Default in C#?
  • one Local Olampyad Questions on Informatic in 2011
  • Obtain ObjectIdHex value from mgo query
  • SVN: Merging two branches together
  • Arrays break string types in Julia
  • KeystoneJS: Relationships in Admin UI not updating
  • Load html files in TinyMce
  • Change div Background jquery
  • How does Linux kernel interrupt the application?
  • Busy indicator not showing up in wpf window [duplicate]
  • Why do underscore prefixed variables exist?
  • Net Present Value in Excel for Grouped Recurring CF