Jump to content

Recommended Posts

Posted (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)

txt_ss.png

hand.png

Edited by cdeb
Posted

You can use Unicode URL decoding/encoding, for example:

#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

ย 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...