problems with upper and lower case

  • Thread starter Thread starter Mr. Novice
  • Start date Start date
M

Mr. Novice

If test is set to all lower case letters both of the
commands listed below will have a return code of 0. How
can I search for only upper or lower case letters in a
string?

The syntax below works great if the string has a number
and your looking for a number. Its just differentiating
between upper and lower case thats causing me grief and
from what I understand A-Z and a-z are both valid
character classes.


echo %test%|findstr /r "[A-Z]"

echo %test%|findstr /r "[a-z]"


Thanks in advance for your help,

Chad
 
If test is set to all lower case letters both of the
commands listed below will have a return code of 0. How
can I search for only upper or lower case letters in a
string?

The syntax below works great if the string has a number
and your looking for a number. Its just differentiating
between upper and lower case thats causing me grief and
from what I understand A-Z and a-z are both valid
character classes.


echo %test%|findstr /r "[A-Z]"

echo %test%|findstr /r "[a-z]"

In W2k/XP (but not NT), the sort order is based on a word sort
algorithm. Alpha characters are sorted in the order aAbBcCdD...zZ.
When you use [A-Z] you are including ALL alpha characters except "a".
If you just want to test for uppercase, you need to explicitly list
the uppercase characters.

echo aBc | findstr [ABCDEFGHIJKLMNOPQRSTUVWXYZ]

Garry
 
Don't know but findstr has a /I switch for ignoring
case which might make your results more consistent.
 
Garry Deane said:
In W2k/XP (but not NT), the sort order is based on a word sort
algorithm. Alpha characters are sorted in the order aAbBcCdD...zZ.
When you use [A-Z] you are including ALL alpha characters except "a".
If you just want to test for uppercase, you need to explicitly list
the uppercase characters.

How did you fid our about this? I haven't seen it documented anywhere.
People who don'y know about it will find the output of findstr baffling in
many cases.

This initially came to my notice when I got unexpected results from
character comparisons on W2k/XP and was discussed in this thread.
http://groups.google.com/groups?q=deane+compare+ascii+alt.msdos.batch.nt

Input from Frank Westlake and Microsoft confirmed the sorting
mechanism. The behaviour of FINDSTR was simply inferred after it too
failed to give expected results on W2k/XP but worked on NT by doing
tests like the following:

echo Y | findstr [a-z]
echo Z | findstr [a-z]
echo a | findstr [A-Z]
echo b | findstr [A-Z]

Mind you, this only explains one facet of FINDSTR's behaviour. There
is other FINDSTR weirdness that has led me to consider it to be flakey
and only trustworthy for simple tasks or after extensive testing.

Garry
 
Back
Top