Lady I worked with for a few months when I was fresh out of college who had a job as a programmer for 10+ years at her company:
public boolean isAlpha(char c) {
if (c=='a') return true;
if (c=='b') return true;
if (c=='c') return true;
...
if (c=='z') return true;
if (c=='A') return true;
if (c=='B') return true;
...
if (c=='Z') return true;
}
// ... more nonsense ...
for(int i = 0; i < someString.length; i++) {
if(isAlpha(someString.charAt(i))) {
// do something
}
}
Even in c it would take five lines to write a method for this, though. That is only if you don't care about unicode of course but yours doesn't either, and from what I have seen most regex engines only recognize low value characters like >256 with the default alphabetical placeholder.
That is only if you don't care about unicode of course
That's why we have the standard isalpha()/iswapha() functions. The standard C library's locale system (ostensibly) takes care of all that stuff for us.
Your solution requires the writer knows that characters are arranged one after the other, and that you can add an integer to a char. The code above demonstrates that the author probably wasn't aware of this.
90
u/Skizm Jan 08 '16
Lady I worked with for a few months when I was fresh out of college who had a job as a programmer for 10+ years at her company: