hisatsu !!! double compile !!!!!!!!!!!!
:shock:
Code:
Public Class morse
Public Shared Function Code(ByVal user As String) As String
Dim result As String = ""
For index = 0 To user.Length - 1
result &= charToMorse(user(index))
Next
Return result
End Function
Private Shared Function charToMorse(ByVal x As Char) As String
Dim result As String = ""
Select Case x
Case "a"
result = "*-"
Case "b"
result = "-***"
Case "c"
result = "-*-*"
Case "d"
result = "-**"
Case "e"
result = "*"
Case "f"
result = "**-*"
Case "g"
result = "--*"
Case "h"
result = "****"
Case "i"
result = "**"
Case "j"
result = "*---"
Case "k"
result = "-*-"
Case "l"
result = "*-**"
Case "m"
result = "--"
Case "n"
result = "-*"
Case "o"
result = "---"
Case "p"
result = "*--*"
Case "q"
result = "--*-"
Case "r"
result = "*-*"
Case "s"
result = "***"
Case "t"
result = "-"
Case "u"
result = "**-"
Case "v"
result = "***-"
Case "w"
result = "*--"
Case "x"
result = "-**-"
Case "y"
result = "-*--"
Case "z"
result = "--**"
Case "0"
result = "-----"
Case "1"
result = "*----"
Case "2"
result = "**---"
Case "3"
result = "***--"
Case "4"
result = "****-"
Case "5"
result = "*****"
Case "6"
result = "-****"
Case "7"
result = "--***"
Case "8"
result = "---**"
Case "9"
result = "----*"
Case "."
result = "*-*-*-"
Case ","
result = "--**--"
Case "?"
result = "**--**"
Case " "
result = "/"
Case Else
End Select
Return result & "/"
End Function
Public Shared Function decoder(ByVal msg As String) As String
Dim result As String = ""
Dim morseChr As String = ""
For index = 0 To msg.Length - 1
If msg(index) <> "/" Then
morseChr &= msg(index)
Else
result &= morseCharToChar(morseChr)
morseChr = ""
End If
Next
result = result.Replace(" ", " ")
'result = result.replaceAll(" ", " ")
Return result
End Function
Private Shared Function morseCharToChar(ByVal x As String) As Char
Dim result As Char = "@"
Select Case x
Case "*-"
result = "a"
Case "-***"
result = "b"
Case "-*-*"
result = "c"
Case "-**"
result = "d"
Case "*"
result = "e"
Case "**-*"
result = "f"
Case "--*"
result = "g"
Case "****"
result = "h"
Case "**"
result = "i"
Case "*---"
result = "j"
Case "-*-"
result = "k"
Case "*-**"
result = "l"
Case "--"
result = "m"
Case "-*"
result = "n"
Case "---"
result = "o"
Case "*--*"
result = "p"
Case "--*-"
result = "q"
Case "*-*"
result = "r"
Case "***"
result = "s"
Case "-"
result = "t"
Case "**-"
result = "u"
Case "***-"
result = "v"
Case "*--"
result = "w"
Case "-**-"
result = "x"
Case "-*--"
result = "y"
Case "--**"
result = "z"
Case "-----"
result = "0"
Case "*----"
result = "1"
Case "**---"
result = "2"
Case "***--"
result = "3"
Case "****-"
result = "4"
Case "*****"
result = "5"
Case "-****"
result = "6"
Case "--***"
result = "7"
Case "---**"
result = "8"
Case "----*"
result = "9"
Case "*-*-*-"
result = "."
Case "--**--"
result = ","
Case "**--**"
result = "?"
Case "/"
result = " "
Case Else
End Select
If result = "@" Then
result = " "
End If
Return result
End Function
End Class
:shock: