in reply to Challenge - Creative Way To Detect Alpha Characters

To all those, including myself, who are using, or had used, two lists (a..z , A..Z): Why not just convert the string to either upper or lower case before working on it so that only 26-element list, instead of 52, would be needed?

In my case ... i didn't even think of it until i was working on the Rexx solution. To repent, below is perl translation....

sub has_alpha { my ($string) = @_; return unless length $string; $string = lc $string; my ($start , $stop) = qw/a z/; while ($start le $stop) { index($string , $start++) != -1 and return 1; } return; }

Replies are listed 'Best First'.
Re^2: Challenge - Creative Way To Detect Alpha Characters
by BrowserUk (Patriarch) on Sep 14, 2004 at 21:50 UTC

    You'd then have to scan the list twice. Once to convert, once to compare.

    The original (and best) solution did 3 passes by both upping and lowing the string and comparing, but all three passes where in C rather than perl, so fast.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    "Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon

      (I removed my comment about the first statement of BrowserUK about which i am still thinking.)

      Yes, you are quite right, BrowserUK, on the point of original solution being the best; it is simple, short, and to the point.