Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local alphabet = {
- ["a"] = ".-",
- ["b"] = "-...",
- ["c"] = "-.-.",
- ["d"] = "-..",
- ["e"] = ".",
- ["f"] = "..-.",
- ["g"] = "--.",
- ["h"] = "....",
- ["i"] = "..",
- ["j"] = ".---",
- ["k"] = "-.-",
- ["l"] = ".-..",
- ["m"] = "--",
- ["n"] = "-.",
- ["o"] = "---",
- ["p"] = ".--.",
- ["q"] = "--.-",
- ["r"] = ".-.",
- ["s"] = "...",
- ["t"] = "-",
- ["u"] = "..-",
- ["v"] = "...-",
- ["w"] = ".--",
- ["x"] = "-.--",
- ["y"] = "-.--",
- ["z"] = "--.."
- }
- function table.hasKey(table, key)
- for k, _ in pairs(table) do
- if k == key then
- return true
- end
- end
- return false
- end
- function convertTxtToMorse(text)
- local result = {}
- for letter in string.lower(text):gmatch(".") do
- if (letter == " ") then
- table.insert(result, " ")
- print("space")
- elseif (not table.hasKey(alphabet, letter)) then
- print("not a letter")
- else
- table.insert(result, alphabet[letter])
- print(alphabet[letter])
- end
- end
- return result
- end
- convertTxtToMorse("test text 1234")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement