E r g e b n i s / R e s u l t
Eine Zeichenkette zu anderen übersetzen
Translate one string to another
B e s c h r e i b u n g / D e s c r i p t i o n
The Translate (XLATE) function alters a string according to rules you pass to it. Although difficult to use at first, this routine is extremely powerful, enabling complex transformations to be made. Using the XLATE function you can replace one or several characters with others. In a sense, this function is similar to the Open Access translate table and printer translation characters.
S y n t a x
Code:
answer = call('XLATE' , string , translate_in , translate_out) P a r a m e t e r
string - any Open Access string
translate_in - this is a string containing the characters that are to be
translated.
translate_out - this string is the same length as translate_in. It
contains the characters that are used to replace the
characters in translate_in.
R e t u r n s
A string, the same length as the input string.
B e i s p i e l / E x a m p l e
Code:
attach 'CONVERT'
! create a test string
a = 'Jackdaws love my big sphinx of quartz'
! create the translation rules. Every occurrence of lowercase 'a' will be
! translated to 'A'
trans_in = 'abcdefghijklmnopqrstuvwxyz'
trans_out = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
! translate the string into uppercase (although you could use UCASE)
! b will contain JACKDAWS LOVE MY BIG SPHINX OF QUARTZ
b = call ('XLATE' , a , trans_in , trans_out)
! create a test string
a = 'oe 123,456.78'
! create the translation rules. Every occurrence of 'oe' is translated to
! '$', ',' to a space, '.' to ','
trans_in = 'oe,.'
trans_out = '$ ,'
! translate the string. b will contain $ 123 456,78
b = call ('XLATE' , a , trans_in , trans_out)
detach 'CONVERT'
! Incidentally, 'Jackdaws love my big sphinx of quartz' is a pangram ie.
! a sentence containing every letter of the alphabet. At 31 characters
! it is shorter than a well know saying involving small carnivores and
! household pets.