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.
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.
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
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.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.