Get string morse code : String « Data Type « VB.Net Tutorial






Public Class Tester
    Public Shared Sub Main
        Dim source As String = "Hello world!"
        Dim characters As String = _
            "~ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,:?'-/"""
        Dim morse() As String = { _
            "?", ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", _
            "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", _
            "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", _
            "-.--", "--..", "-----", ".----", "..---", "...--", _
            "....-", ".....", "-....", "--...", "---..", "----.", _
            ".-.-.-", "--..--", "---...", "..--..", ".----.", _
            "-....-", "-..-.", ".-..-."}

        Dim counter As Integer
        Dim position As Integer

        For counter = 0 To source.Length - 1
            position = characters.IndexOf(Char.ToUpper( _
               source.Chars(counter)))
            If (position < 0) Then position = 0
            Console.Write (source.Substring(counter, 1) & "   ")
            Console.WriteLine(morse(position))
        Next counter

    End Sub


End Class
H   ....
e   .
l   .-..
l   .-..
o   ---
    ?
w   .--
o   ---
r   .-.
l   .-..
d   -..
!   ?








2.26.String
2.26.1.Declare String Variable and assign value
2.26.2.String.Empty
2.26.3.Demonstrating String class constructors
2.26.4.Join string
2.26.5.Copy characters from string1 into character Array
2.26.6.String Length property
2.26.7.Demonstrating method GetHashCode of class String
2.26.8.Insert sub string by index
2.26.9.Insert method returns the resulting string
2.26.10.SubString
2.26.11.Get string morse code
2.26.12.String operation timing
2.26.13.Change tab to space
2.26.14.ToString
2.26.15.Catch Exception for String.Substring
2.26.16.Count Vowels
2.26.17.Reverse a string
2.26.18.Make a reference copy
2.26.19.Check a Credit card number
2.26.20.Read String value from Keyboard