function charToIdx( %char )
{
if ( strLen( %char ) != 1 )
{
return -1;
}
%count = 16;
%hex = “0123456789ABCDEF“;
for ( %x = 0 ; %x < %count ; %x++ )
{
for ( %y = 0 ; %y < %count ; %y++ )
{
if ( strStr( %char, collapseEscape( “\\x“ @ getSubStr( %hex, %x, 1 ) @ getSubStr( %hex, %y, 1 ) ) ) == 0 )
{
return %x + %y;
}
}
}
return -1;
}
function idxToChar( %idx )
{
if ( !strLen( %idx ) || %idx < 0 || %idx > 254 )
{
return ““;
}
%count = 16;
%hex = “0123456789ABCDEF“;
for ( %x = 0 ; %x < %count ; %x++ )
{
for ( %y = 0 ; %y < %count ; %y++ )
{
if ( %x + %y == %idx )
{
return collapseEscape( “\\x“ @ getSubStr( %hex, %x, 1 ) @ getSubStr( %hex, %y, 1 ) );
}
}
}
return ““;
}
Sorry for the lack of proper identation, I coded this on a tiny phone keyboard.
charToIdx( char ) => ASCII index of char (0-254).
idxToChar( idx ) => Character representation of the ASCII index.