const morse_code = [["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", "--.."], ["0", "-----"], ["1", ".----"], ["2", "..---"], ["3", "...--"], ["4", "....-"], ["5", "....."], ["6", "-...."], ["7", "--..."], ["8", "---.."], ["9", "----."]] fn main() { str := "this is a test text" mut strmorse := "" for n, _ in str { if str[n].ascii_str() ==" " {strmorse += " "} for m, _ in morse_code { if morse_code[m][0] == str[n].ascii_str() {strmorse += morse_code[m][1] + "|"} } } println(strmorse.all_before_last("|")) }