Want a wicked tech puzzle?
A А A
Which letter out of three is Cyrillic? Discerning characters gets really hard when they look same. It may be nothing but it also might create obscure and invisible code errors. So I made tiny AutoIt app that allows to easily check codes of characters and characters for given codes.
Create GUI
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
$gui=GUICreate("Character codes",200,60)
$chars=GUICtrlCreateInput("",0,0,200,20)
$codes=GUICtrlCreateInput("",0,41,200,20)
$asc=GUICtrlCreateRadio("ASCII",30,21,50,20)
$ascw=GUICtrlCreateRadio("Unicode",111,21,1000,20)
GUICtrlSetState($asc,$GUI_CHECKED)
GUISetState()
$lastchars=""
$lastcodes=""
Nothing overly fancy:
- necessary includes;
- two inputs for code and characters plus ASCII/Unicode encoding selectors;
- choosing ASCII by default and initializing last known values as empty.
Main loop
Without main parts of code, see below for those.
While 1
$msg = GUIGetMsg()
Select
Case GUICtrlRead($chars)<>$lastchars
[...]
Case GUICtrlRead($codes)<>$lastcodes
[...]
Case $msg = $asc Or $msg = $ascw
$lastchars=""
$lastcodes=""
Case $msg = $GUI_EVENT_CLOSE
Exit
EndSelect
WEnd
Code waits for either characters or code inputs to change. When any changes app calculates and updates another input accordingly.
If encoding is changed values are reset so inputs are refreshed.
Convert symbols
$string=GUICtrlRead($chars)
$string=StringSplit($string,'',2)
$output=""
$ascii=BitAND(GUICtrlRead($asc), $GUI_CHECKED)
For $symbol In $string
If $ascii Then
$output&=Asc($symbol)&" "
Else
$output&=AscW($symbol)&" "
EndIf
Next
GUICtrlSetData($codes,$output)
$lastchars=GUICtrlRead($chars)
$lastcodes=GUICtrlRead($codes)
Main code (similar for two cases so I only include one here):
- reads input and splits it into array of characters (/codes);
- gets chosen encoding;
- calls according function to convert for each array item and adds to result;
- sets result to another input and updates last known state.
Overall
And answer to the puzzle is absolutely obvious with this one:
Script https://www.rarst.net/script/asc.au3