• We just launched and are currently in beta. Join us as we build and grow the community.

Unicode to HTML Converter in Visual Basic

P4R0DY

Search Guru
P Rep
0
0
0
Rep
0
P Vouches
0
0
0
Vouches
0
Posts
163
Likes
123
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 400 XP
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. Dim

    entries As

    String

    () = {""

    ""

    , "quote"

    , "£"

    , "pound"

    }
  3. Dim

    eqs As

    String

    () = {"""

    , """

    , "£"

    , "£"

    }

  4. Private

    Sub

    Button1_Click(sender As

    Object

    , e As

    EventArgs) Handles Button1.Click
  5. Dim

    user As

    String

    = TextBox1.Text
  6. Dim

    ind As

    Integer

    = Nothing
  7. For

    i As

    Integer

    = 0 To

    entries.Count - 1
  8. If

    (user.ToLower() = entries(i).ToLower()) Then

    ind = i
  9. Next
  10. If

    (ind = Nothing

    ) Then
  11. MsgBox("That unicode character(s) was not found!"

    )
  12. Else
  13. MsgBox(eqs(ind))
  14. End

    If
  15. End

    Sub
  16. End

    Class

 

452,292

323,526

323,535

Top