;========================================================================================================================================== ; ; How to convert HTML entities to unicode characters? ; ; Example 1: Convert one decimal or hex entity code point. ; Example 2: Convert a text string, which contains named, decimal or hex entity code points. ; ; (c)Detlev Dalitz.20111207. ;========================================================================================================================================== ; Set work folder to script folder. DirChange (DirScript ()) ; Example 1. strHtmlNumEntity = "Ş" ; Decimal. strHtmlNumEntity = "Ş" ; Hex. strHtmlNumEntity = "Ş" ; Hex. strNum = StrClean (strHtmlNumEntity, "&#;", "", @TRUE, 1) If 1 == StrIndexNC (strNum, "x", 1, @FWDSCAN) strNum = StrFixLeft (StrSub (strNum, 2, -1), "0", 4) strTextUnicode = ChrHexToUnicode (StrSub (strNum : strNum, 3, 4)) Else hdlBB = BinaryAlloc (2) BinaryPoke2 (hdlBB, 0, Int (strNum)) strTextUnicode = ChrHexToUnicode (BinaryPeekHex (hdlBB, 0, 2)) hdlBB = BinaryFree (hdlBB) EndIf ClipPut (strTextUnicode) AskLine ("Decode decimal or hex HTML numerical entity", "Result", strTextUnicode, 1) ; Example 2. strTextHtmlEntities = "¿Hablas bien el español? <<< Yönetim Danısmanlık A.Ş. >>>" objIE = ObjectOpen ("InternetExplorer.Application") objIE.visible = @FALSE objIE.navigate("about:blank") objTA = objIE.Document.createElement("textarea") objTA.innerHTML = StrReplace (StrReplace (strTextHtmlEntities, "<", "<"), ">", ">") strTextUnicode = objTA.value objIE.quit objTA = 0 objIE = 0 ClipPut (strTextUnicode) AskLine ("Decode decimal or hex or named HTML entities", "Result", strTextUnicode, 1) :CANCEL Exit