[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Translating text to EBCDIC
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Wed, 24 Sep 2008 10:30:12 -0300
> Usually this is done with a table lookup, i.e. the character to be
> translated is used as a binary offset into a 256 byte table of the
> translated characters. Thus at position X'41' in this table would be x'C1'
> facilitating the translation of the ASCII 'A' into its EBCDIC equivalent.
> How does one go about doing this in Lua?
In exactly the same way: string.gsub accepts a table for replacements.
Something like this:
string.gsub(ASCIItext,".",ASCII2EBCDIC)
where ASCII2EBCDIC = { [string.char(0x41)] = string.char(0xC1), ... }
If you have the ASCII to EBCDIC conversion table in textual form,
it's usually simple to write a parser in Lua that builds the table above
automatically.