On Dec 4, 2007 8:04 AM, Deepak Gupta <[EMAIL PROTECTED]> wrote:
> Can anyone tell me or  point me to a Macro or coldfusion code to convert 
> letters to numbers on phone keypad. For example
> ABDG will be 2234
> And this way I have a lot of Names in database and I have to pick first 4 
> letters from the name and convert them into 4 digit codes from phone keypad.

<cffunction name="lettersToPhone" returntype="string" output="false">
        <cfargument name="stringToConvert" type="string" required="true" />

        <cfset var str          = left(stringToConvert, 4) />
        <cfset var retStr       = "" />
        <cfset var idx          = "" />

        <cfloop from="1" to="#len(str)#" index="idx">
                <cfswitch expression="#mid(str, idx, 1)#">
                        <cfcase value="a,b,c">
                                <cfset retStr = retStr & "2" />
                        </cfcase>
                        <cfcase value="d,e,f">
                                <cfset retStr = retStr & "3" />
                        </cfcase>
                        <cfcase value="g,h,i">
                                <cfset retStr = retStr & "4" />
                        </cfcase>
                        <cfcase value="j,k,l">
                                <cfset retStr = retStr & "5" />
                        </cfcase>
                        <cfcase value="m,n,o">
                                <cfset retStr = retStr & "6" />
                        </cfcase>
                        <cfcase value="p,q,r,s">
                                <cfset retStr = retStr & "7" />
                        </cfcase>
                        <cfcase value="t,u,v">
                                <cfset retStr = retStr & "8" />
                        </cfcase>
                        <cfcase value="w,x,y,z">
                                <cfset retStr = retStr & "9" />
                        </cfcase>
                </cfswitch>
        </cfloop>

        <cfreturn retStr />
</cffunction>

<cfoutput>#lettersToPhone('ABDG')#</cfoutput>

-- 
"Scientists tell us that the fastest animal on earth, with a top speed
of 120 feet per second, is a cow that has been dropped out of a
helicopter." - Dave Barry

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion is delivering applications solutions at at top companies 
around the world in government.  Find out how and where now
http://www.adobe.com/cfusion/showcase/index.cfm?event=finder&productID=1522&loc=en_us

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:294183
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to