Link to home
Start Free TrialLog in
Avatar of ho_alan
ho_alan

asked on

web-based UTF encoder.

I would like to know how to convert chinese characters into hex string in vb.net?

thanks a lot!!!
Avatar of smallee
smallee

try this

Imports System.Text
Public Class chiutfencoding
    Inherits System.Web.UI.Page
    Dim UniEnc As UnicodeEncoding = New UnicodeEncoding(True, True)
    Dim UTF8Enc As UTF8Encoding = New UTF8Encoding
    Dim UTF7Enc As UTF7Encoding = New UTF7Encoding

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents lblInput As System.Web.UI.WebControls.Label
    Protected WithEvents txtInput As System.Web.UI.WebControls.TextBox
    Protected WithEvents butShowByte As System.Web.UI.WebControls.Button
    Protected WithEvents lblUTF16 As System.Web.UI.WebControls.Label
    Protected WithEvents lblUTF8 As System.Web.UI.WebControls.Label
    Protected WithEvents lblUTF7 As System.Web.UI.WebControls.Label
    Protected WithEvents txtUTF16 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtUTF8 As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtUTF7 As System.Web.UI.WebControls.TextBox

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
    End Sub

    Private Sub butShowByte_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butShowByte.Click
        txtUTF16.Text = ShowByte(txtInput.Text, "UTF-16")
        txtUTF8.Text = ShowByte(txtInput.Text, "UTF-8")
        txtUTF7.Text = ShowByte(txtInput.Text, "UTF-7")
    End Sub

    Function ShowByte(ByVal inStr As String, ByVal encode As String) As String
        Dim result As String
        Dim bArray() As Byte
        result = ""
        Select Case encode
            Case "UTF-16"
                bArray = UniEnc.GetBytes(inStr)
            Case "UTF-8"
                bArray = UTF8Enc.GetBytes(inStr)
            Case "UTF-7"
                bArray = UTF7Enc.GetBytes(inStr)
        End Select
        Dim len As Integer = bArray.Length
        For i As Integer = 0 To len - 1
            result = result & " " & Hex(bArray(i))
        Next
        Return result
    End Function
End Class
Avatar of ho_alan

ASKER

let me try the codes now
thanks!
ASKER CERTIFIED SOLUTION
Avatar of ee_ai_construct
ee_ai_construct
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial