Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local d, digits, alpha = '01230120022455012623010202', {}, string.byte("A")
- string.gsub(d, ".", function(c)
- digits[string.char(alpha)] = c
- alpha = alpha + 1
- end)
- local function Soundex(w)
- local res = {}
- for c in string.gmatch(string.upper(w), ".") do
- local d = digits[c]
- if d then
- if #res==0 then
- res[1] = c
- elseif #res==1 or d~= res[#res] then
- res[1+#res] = d
- end
- end
- end
- if #res == 0 then
- return '0000'
- else
- res = string.gsub(table.concat(res), "0", "")
- return string.sub(res .. '0000',1,4)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement