Hello
I need to convert a ISO-8859-1 to UTF-8 so that I can create a barcod with croatian font (ČĆŽŠĐ). I tried this code but did not get the Croatian letters
Code:
Public Function Utf8BytesFromString(strInput As String) As Byte()
Dim nBytes As Long
Dim abBuffer() As Byte
' Catch empty or null input string
Utf8BytesFromString = vbNullString
If Len(strInput) < 1 Then Exit Function
' Get length in bytes *including* terminating null
nBytes = WideCharToMultiByte(CP_UTF8, 0&, ByVal StrPtr(strInput), -1, 0&, 0&, 0&, 0&)
' We don't want the terminating null in our byte array, so ask for `nBytes-1` bytes
ReDim abBuffer(nBytes - 2) ' NB ReDim with one less byte than you need
nBytes = WideCharToMultiByte(CP_UTF8, 0&, ByVal StrPtr(strInput), -1, ByVal VarPtr(abBuffer(0)), nBytes - 1, 0&, 0&)
Utf8BytesFromString = abBuffer
'MsgBox nBytes
End Function
input "ČÅ " OUTPUT Ȋ
I TRIED TOO
Code:
Public Function tlhAsciiToUtf8(ByRef strText As String) As String
Dim hexString As Long
Dim newval As Long
hexString = Val("&h" & strText)
If hexString <= 127 Then
tlhAsciiToUtf8 = "%" & strText
ElseIf hexString <= 191 Then
tlhAsciiToUtf8 = "%C2%" & strText
ElseIf hexString <= 255 Then
newval = 49856 + hexString
tlhAsciiToUtf8 = "%" & Mid(Hex(newval), 1, 2) & "%" & Mid(Hex(newval), 3, 2)
Else
MsgBox ("NON ASCII CHARACTER: " & hexString)
End If
End Function
same thing
please help