Well, this implementation is a bit faster (but less readable)
bool isAlphabeticOnly(String strin) {
// comparison with 0 - "i >= 0" - is faster than with strin.Length
for (int i = strin.Length - 1; i >= 0; --i) {
char c = strin[i];
if ((c < 'a' || c > 'z') && (c < 'A' || c > 'Z'))
return false;
}
return true;
}
At my workstation (.net 4.5, IA64, Core i5 3.2GHz) average times are
Initial 2100 ms
This 1600 ms
Measuring
// Yes, very long string
String test = new String('p', 100000000) + new String('Q', 100000000);
Stopwatch sw = new Stopwatch();
sw.Start();
isAlphabeticOnly(test);
sw.Stop();
However, if you experience real performance problems, it's not isAlphabeticOnly
where you should solve it.