Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert telephone letters to numbers 1

Status
Not open for further replies.

PhilBreau

Technical User
Dec 14, 2001
108
CA
I'm looking for an efficient way of converting telephone keypad letters to numbers. I want to write a script which will convert a string "SMITH" to 76484.

A,B,C is 2
D,E,F is 3

and so on


Thank you
 
Here's a quick example I whipped up showing how I would probably do this:

proc main
string sInput = "AbCXYZ"
integer iLen
integer iLoop
string sChar

strlen sInput iLen
for iLoop = 0 upto iLen
substr sChar sInput iLoop 1
switch sChar
case "a"
case "b"
case "c"
case "A"
case "B"
case "C"
strputc sInput iLoop '2'
endcase
endswitch
endfor
usermsg "%s" sInput
endproc

You could reduce the number of case statements in half by using the strupr command on sInput to make sure the string is uppercase, thereby eliminating case "a", case "b", and case "c" from my example.


aspect@aspectscripting.com
 
Knob,

Wow! That was quick.

As always, your replies are greatly appreciated.

I had a little trouble getting it to work. I know you put it together quickly. Is the following modification what you would have in mind? Or maybe you provided something for starters and I had to complete it? Either way have a star and

Thank you



strlen sInput iLen
for iLoop = 0 upto iLen
substr sChar sInput iLoop 1
switch sChar
case "A"
case "B"
case "C"
strputc sInput iLoop '2'
endcase

case "D"
case "E"
case "F"
strputc sInput iLoop '3'
endcase

case "G"
case "H"
case "I"
strputc sInput iLoop '4'
endcase

and so on
 
Sorry, I was a little rushed for time and didn't finish off my comments. The way you have listed, with three additional case statements followed by the appropriate strputc command, is the way I envisioned it being.

aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top