cdeb Posted February 20, 2020 Share Posted February 20, 2020 (edited) I can't write an emoji character on a txt file I copy the character to the system clipboard, taking it for example from here https://emojipedia.org/backhand-index-pointing-right/ 👉 I use the ClipGet() function to store the value in a variable. $emoji= ClipGet() and write it on the txt file FileWrite($hFileOpen, "$emoji: "& $emoji & @CRLF) I see the relative Asc and AscW values $iAscii = Asc($emoji) $iUTF8 = AscW($emoji) ConsoleWrite("Tsadi: $iAscii = 0x" & Hex($iAscii) & "(invalid) -- $iUTF8 = 0x" & Hex($iUTF8) & "(invalid) -- $iUTF8 = " & $iUTF8 & @LF)  So far everything is ok, but if I want to write it directly without copying it from the system clipboard, something does not work In fact, when trying to convert the unicode code '55357' to its character, this is not displayed correctly Local $hFileOpen = FileOpen($sFilePath, $FO_OVERWRITE+$FO_UNICODE) FileWrite($hFileOpen, "$emoji ClipGet(): "& $emoji & @CRLF) FileWrite($hFileOpen, "Chr $iAscii:"& Chr($iAscii) & @CRLF) FileWrite($hFileOpen, "ChrW $iUTF8:"& ChrW($iUTF8) & @CRLF) FileWrite($hFileOpen, "ChrW $iAscii:"& ChrW($iAscii) & @CRLF) FileWrite($hFileOpen, "Chr $iUTF8:"& Chr($iUTF8) & @CRLF)  I also did other tests but nothing  $emoji ClipGet(): 👉 Chr $iAscii:? ChrW $iUTF8:� ChrW $iAscii:? Chr $iUTF8:  full code: $emoji= ClipGet() ConsoleWrite('$emoji:' & @TAB & $emoji& @CRLF) $iAscii = Asc($emoji) $iUTF8 = AscW($emoji) ConsoleWrite("Tsadi: $iAscii = 0x" & Hex($iAscii) & "(invalid) -- $iUTF8 = 0x" & Hex($iUTF8) & "(invalid) -- $iUTF8 = " & $iUTF8 & @LF) Local Const $sFilePath = @TempDir & "\FileWrite.txt" Local $hFileOpen = FileOpen($sFilePath, $FO_OVERWRITE+$FO_UNICODE) FileWrite($hFileOpen, "$emoji ClipGet(): "& $emoji & @CRLF) FileWrite($hFileOpen, "Chr $iAscii:"& Chr($iAscii) & @CRLF) FileWrite($hFileOpen, "ChrW $iUTF8:"& ChrW($iUTF8) & @CRLF) FileWrite($hFileOpen, "ChrW $iAscii:"& ChrW($iAscii) & @CRLF) FileWrite($hFileOpen, "Chr $iUTF8:"& Chr($iUTF8) & @CRLF) Edited February 20, 2020 by cdeb Link to comment Share on other sites More sharing options...
Subz Posted February 21, 2020 Share Posted February 21, 2020 You can use Unicode URL decoding/encoding, for example: expandcollapse popup#include <File.au3> Local $sEmojiOrg = "👉" Local $sEmojiEnc = _UnicodeURLEncode($sEmojiOrg) Local $sFilePath = @TempDir & "\FileWrite.txt" Local $hFileOpen = FileOpen($sFilePath, $FO_OVERWRITE) FileWrite($hFileOpen, "Encoded: " & $sEmojiEnc & @CRLF) FileWrite($hFileOpen, "Decoded: " & _UnicodeURLDecode($sEmojiEnc) & @CRLF) FileClose($hFileOpen) ShellExecute($sFilePath) ;=============================================================================== ; _UnicodeURLEncode() ; Description: : Encodes an unicode string to be URL-friendly ; Parameter(s): : $UnicodeURL - The Unicode String to Encode ; Return Value(s): : The URL encoded string ; Author(s): : Dhilip89 ; Note(s): : - ; ;=============================================================================== Func _UnicodeURLEncode($UnicodeURL) $UnicodeBinary = StringToBinary ($UnicodeURL, 4) $UnicodeBinary2 = StringReplace($UnicodeBinary, '0x', '', 1) $UnicodeBinaryLength = StringLen($UnicodeBinary2) Local $EncodedString For $i = 1 To $UnicodeBinaryLength Step 2 $UnicodeBinaryChar = StringMid($UnicodeBinary2, $i, 2) If StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", BinaryToString ('0x' & $UnicodeBinaryChar, 4)) Then $EncodedString &= BinaryToString ('0x' & $UnicodeBinaryChar) Else $EncodedString &= '%' & $UnicodeBinaryChar EndIf Next Return $EncodedString EndFunc ;==>_UnicodeURLEncode ;=============================================================================== ; _UnicodeURLDecode() ; Description: : Tranlates a URL-friendly string to a normal string ; Parameter(s): : $toDecode - The URL-friendly string to decode ; Return Value(s): : The URL decoded string ; Author(s): : nfwu, Dhilip89 ; Note(s): : Modified from _URLDecode() that's only support non-unicode. ; ;=============================================================================== Func _UnicodeURLDecode($toDecode) Local $strChar = "", $iOne, $iTwo Local $aryHex = StringSplit($toDecode, "") For $i = 1 To $aryHex[0] If $aryHex[$i] = "%" Then $i = $i + 1 $iOne = $aryHex[$i] $i = $i + 1 $iTwo = $aryHex[$i] $strChar = $strChar & Chr(Dec($iOne & $iTwo)) Else $strChar = $strChar & $aryHex[$i] EndIf Next $Process = StringToBinary (StringReplace($strChar, "+", " ")) $DecodedString = BinaryToString ($Process, 4) Return $DecodedString EndFunc ;==>_UnicodeURLDecode #endregion Original UDF  Link to comment Share on other sites More sharing options...
cdeb Posted February 21, 2020 Author Share Posted February 21, 2020 perfect thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now