lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> 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.