Download code

Jump to: navigation, search

Back to Soundex_(Rexx)

Download for Windows: single file, zip

Download for UNIX: single file, zip, tar.gz, tar.bz2

soundex_test.rexx

 1 /* The authors of this work have released all rights to it and placed it
 2 in the public domain under the Creative Commons CC0 1.0 waiver
 3 (http://creativecommons.org/publicdomain/zero/1.0/).
 4 
 5 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 6 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 7 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 8 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 9 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
11 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 
13 Retrieved from: http://en.literateprograms.org/Soundex_(Rexx)?oldid=18729
14 */
15 
16 Do Forever
17    Call LineOut , "Enter the name: "
18    Name = LineIn()
19    If Name = "" then Leave
20    Say "SOUNDEX value = " || Soundex(Name)
21 End
22 Exit 0
23 
24 /* ------------------------------------------------------------------------ */
25 /* code = Soundex(name)                                                     */
26 /*                                                                          */
27 /* Compute and return the SOUNDEX code corresponding to the specified name. */
28 /* ------------------------------------------------------------------------ */
29 Soundex: Procedure
30    Source = Arg(1)
31 
32    Result = Left(Source, 1)
33 
34    SoundexNum = "01230127022455012623017202"
35               /* ABCDEFGHIJKLMNOPQRSTUVWXYZ */
36 
37    Source = Translate(Source, SoundexNum, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "7")
38    Source = Space(Translate(Source, " ", "7"), 0)
39    Do I = 1 to Length(Source)
40       Do J = I+1 to Length(Source) While Substr(Source, I, 1) = Substr(Source, J, 1)
41          Source = Left(Source, J-1) || "0" || Substr(Source, J+1)
42       End
43    End
44    Result = Result || Space(Translate(Substr(Source, 2), " ", "0"), 0)
45    Result = Left(Result, 6, "0")
46 
47 Return Result


hijacker
hijacker
hijacker
hijacker