This week we're going to write a function to convert letters to their corresponding soundex codes. But wait, there's more! We'll also allow you to pass in an entire string and convert the whole thing. Here's the set up:
function soundex(someString)
if len(someString) = 1 then
' code to convert a single character
else
' loop through the whole string and convert each character
end if
end function
Inside the loop, we'll recursively call the soundex function to convert the individual character. Actually, this may not perfectly fit the definition of recursion. The only recursive aspect of it is that the function calls itself, but an entirely different execution path is being followed once inside. But that's good, because we won't have the poor performance that sometimes comes with recursion.
Once again, the full source code is a little too long to post, so you'll have to grab it from Snipplr:
No comments:
Post a Comment