21 lines
897 B
VB.net
21 lines
897 B
VB.net
Imports System.Text
|
|
|
|
Public Class ClassHelper
|
|
Public Shared Function encode_utf8(ByVal str As String) As String
|
|
Try
|
|
'supply True as the construction parameter to indicate
|
|
'that you wanted the class to emit BOM (Byte Order Mark)
|
|
'NOTE: this BOM value is the indicator of a UTF-8 string
|
|
Dim utf8Encoding As New System.Text.UTF8Encoding(True)
|
|
Dim encodedString() As Byte
|
|
encodedString = utf8Encoding.GetBytes(str)
|
|
If LogErrorsOnly = False Then ClassLogger.Add(String.Format(" >> String {0} was encoded via utf8 to {1}", str, utf8Encoding.GetString(encodedString)))
|
|
Return utf8Encoding.GetString(encodedString)
|
|
Catch ex As Exception
|
|
ClassLogger.Add("Unexpected error in encode_utf8: " & ex.Message)
|
|
Return Nothing
|
|
End Try
|
|
|
|
End Function
|
|
End Class
|