I realize that any difference would be minor, but don't
we always want to write the best code we can? ;-)
That depends on what you mean by "best". The fastest code that can be
written in VB almost always involves making extensive amounts of API
function calls. Such code tends to involve large amounts of code lines which
end up being nearly impossible to read in the end, but will tend to be
magnitudes faster than any code you write using standard built-in VB
function. Are you advocating writing all your code this way because it will
always be much, much, much faster in the end? Your answer should be "No", by
the way, because the time involved in writing such code, especially for
those not familiar with API functions, would be unreasonable, not to mention
a maintenance nightmare.
I did want to say something about your initial posting by the way. You
originally wrote...
"For example, for the alphabet is 'etaoin'..."
giving us the impression that the number of characters in your "alphabets"
were somewhat small. I realized you were just "simplifying" the question for
us, but I would like to suggest that you not do that for future questions
you ask. If it were indeed the case that your alphabets were 6, 7, 8 or so
characters long, then the code I posted would have almost always been faster
than the other code submissions you received (it was designed that way).
However, once you told us your alphabets were always 26 characters long, my
code lost it advantage. With a 26-character alphabet, your test strings
would need to be, on average, around 14 characters long (or longer) for my
code to be almost always faster... the boundary length being
2*Len(TestString)-1. The point I am trying to make here is that if you
simplify your questions us, then we will give you solutions, sometimes
really good ones, for a situation you do not actually have. It is better to
tell your exact setup so we can design our answers for the question that you
actually have.
Rick Rothstein (MVP - Excel)