I have this code

for /l %%a in (0, 1, 25) do (
if /i !TextAlphabet!==!Alphabet[%%a]! (
set AlphabetNumber=%%a

!Alphabet[]! is an array containing alphabets.

I tried echoing !TextAlphabet! and !Alphabet[%%a]! and when they are the same, %AlphabetNumber% is still the value I set before the loop.

I tried checking for white spaces in my variables but found none.

I also tried adding the variables in a "" tag.

  • This question appears to be off-topic because it is about programming and belongs on Stack Overflow. Try stackoverflow.com/help/how-to-ask – Kevin Panko Feb 22 '14 at 16:14
  • 5
    @KevinPanko The question is fine here. We allow scripting questions that pertain to power user environments and system administration. – slhck Feb 24 '14 at 11:54

If you want to check if a variable contains only letters you could use findstr, like this:

set var=Abc
echo %var%|findstr "^[A-Za-z]*$" >nul
if %errorlevel% == 0 (echo Variable is alphabetical)

How it works

The variable is echoed and then piped to the findstr command, which will use a regular expression to match alphabetical characters:

  • ^ matches beginning of line;
  • [A-Za-z] defines a character class which matches any character from A to Z, both upper case and lower case;
  • * repeats zero or more occurrences of the previous class;
  • $ matches end of line.

The %errorlevel% variable will be set to 0 if there's a match, or 1 otherwise. The findstr output will be then redirected to nul, thus ignored.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.