TransTable
TransTable
Stack | Position | Description |
---|---|---|
Stack(In) | Top | Character string |
Stack(Out) | Top | - |
A translation table for the Translate statement is created. The string contains an even number of characters: Z0 Z'0 ... Zi Z'i ... with the statement that every character Zk is replaced by Z'k during translation.
The translation table also takes effect when reading a file with the class CX_ASCII_FILE and can be used to read files in non-ASCII formats such as EBCDIC.
The pairs of characters that define the translation can all be combined into a single string. However, it is also possible to pass a vector:
Stack | Position | Description |
---|---|---|
Stack(In) | Top | a vector |
Stack(Out) | Top | - |
The vector elements are strings.
The following lines are equivalent, for example:
"0a1b2c3d" TransTable [ "0a" "1b" "2c" "3d" ] TransTable [ "0a1b" "2c3d" ] TransTable
Code example: Reading in an EBCDIC-encoded file using a translation table to Windows-1252
// An (incomplete!) EBCDIC->Windows1252 translation table [ "\xC1\x41\xC2\x42\xC3\x43" // ABC "\xD1\x4A\xD2\x4B\xD3\x4C" // JKL "\xF0\x30\xF1\x31\xF2\x32" // 012 "\xA1\x7E\x4A\xA2\xE7\x3D" // ~¢= "\x30\x81\x31\x81" // undefined ebcdic codes ] TransTable CreateTransObject(CX_ASCII_FILE) -> file // Set encoding to Windows1252, because the translation table above specifies // the conversion of bytes from EBCDIC to Windows1252. "windows1252" file Call(SetCodepage) "ebcdic-file.txt" file Put(fileName) file Call(Read) // process data