Find a letter on a position in the Alphabet
Just needed a quick way to find a letter in the alphabet on a postion.
So for example, postion 1 returns 'A' and position 26 returns 'Z'.
Step 1: Function
<cfargument name="position" type="numeric" required="true">
<!--- Thanks to Ryan and Shane..... --->
<cfif arguments.position gte 1 and arguments.position lte 26>
<cfreturn chr(64+arguments.position) />
<cfelse>
<cfreturn "not in alphabet">
</cfif>
</cffunction>
Step 2: Call function
returns: Z


<cfif arguments.position gte 1 and arguments.position lte 26>
<cfreturn chr(64+arguments.position) />
</cfif>
<cfreturn chr(64+arguments.position) />
generating an array every time you need this function does not seem necessary... you could store the array in a persistant scope.
But, actually my question is, why don't you simply do
#chr(64+x)#
where x is the position in the alphabet?
Chris
#chr(64=x) seems to be perfect at times. At other times I think it's nice to have the implementation hidden in a method that is explaining by name what it is doing.
@ Ernst
I would like to have a more formal exception instead of the string ''not in alphabet".
That makes reusing the method more tempting to me.