PDA

View Full Version : Special chars to UTF-8



pulsar777
03-11-2019, 12:37 PM
Hi, I have array with words that contain special characters found in German language
and I'd like to convert that array to UTF-8 encoded words equivalent.

Thanks for any advice!

大灰狼1976
03-11-2019, 07:13 PM
Hi pulsar777!
The code found on the Internet, but I don't understand either.

Sub Test()
Debug.Print Sp2Utf8("special characters") 'you can input special characters here
End Sub
Function Sp2Utf8(szCode As String)
With CreateObject("MSScriptControl.ScriptControl")
.Language = "JavaScript"
.addcode "function decode(str){return escape(str).replace(/%/g,'\\')}"
Sp2Utf8 = .Eval("decode('" & szCode & "')")
End With
End Function

pulsar777
03-13-2019, 09:36 AM
Thanks man ! Even the regular expressions you posted don't do the trick.
I found out those inputs to database are iso-8859-2 encoded, but db automatically changes it to utf-8 (coverts special chars to weird symbols)
And I think that's why it cannot convert those symbols back from db to front-end.

snb
03-15-2019, 07:46 AM
Use:


Private Declare Function OemToCharA Lib "user32.dll" (ByVal lpszSrc As String, ByVal lpszDst As String) As Long

Public Function F_ASC_ANS(ByVal Text As String) As String
OemToCharA Text, Text
F_ASC_ANS = Text
End Function

Sub M_snb()
MsgBox F_ASC_ANS("äëïöüß")
End Sub