Unicode to HTML Converter in Visual Basic

Introduction: This tutorial is on how to create a unicode to HTML equivilient characters. Design: This design requires two components; Textbox, textbox1, User entries Button, button1, Begins process. Variables: The way this system will work is it will search one array or list of information for the entry from the user, get the inex and return the element at the same index but in a different list, the information's equivilient partner. So first we need the two lists, we'll call the user entries list 'entries', and the equivilients list 'eqs'...
  1. Dim entries As String() = {"""", "quote", "£", "pound"}
  2. Dim eqs As String() = {""", """, "£", "£"}
I have only included a few unicode & HTML characters, you can add an entire range by performing a simple Google search. Button Click: Now, on the button mouse click, we want to retrieve the entered text by the user and store it in a new variable named 'user'...
  1. Dim user As String = TextBox1.Text
We then want to find the index in the 'entries' list that matches the users entry, all converted to lower case so there are no minimal discrepancies...
  1. Dim ind As Integer = Nothing
  2. For i As Integer = 0 To entries.Count - 1
  3. If (user.ToLower() = entries(i).ToLower()) Then ind = i
  4. Next
Next we want to use the stored index in the integer variable 'ind' to msgbox out the element at that integer position/index of the 'eqs' list...
  1. If (ind = Nothing) Then
  2. MsgBox("That unicode character(s) was not found!")
  3. Else
  4. MsgBox(eqs(ind))
  5. End If
Finished! Here's the full source code:
  1. Public Class Form1
  2.  
  3. Dim entries As String() = {"""", "quote", "£", "pound"}
  4. Dim eqs As String() = {""", """, "£", "£"}
  5.  
  6. Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
  7. Dim user As String = TextBox1.Text
  8. Dim ind As Integer = Nothing
  9. For i As Integer = 0 To entries.Count - 1
  10. If (user.ToLower() = entries(i).ToLower()) Then ind = i
  11. Next
  12. If (ind = Nothing) Then
  13. MsgBox("That unicode character(s) was not found!")
  14. Else
  15. MsgBox(eqs(ind))
  16. End If
  17. End Sub
  18. End Class

Add new comment