Replaces all characters of a string expression with values from a table.
$ = Xlate[$](a$, mi())
$ = Xlate[$](a$, m$())
$ = Xlate[$](a$, addr)
a$:sexp
mi():integer array variable (%,&,|)
m$():string array variable
addr:iexp
Xlate$(a$, m()) converts each character in the string expression a$ using the user-created table in m(). The array can be of any integer type (Byte, Short, Card or Integer/Long).
The character of the string is replaced with value in the array at the index which corresponds with the ASCII code of the character. For instance, when the string a$ contains the character 'A', then it is replaced with the character value at index = 65 in the array, because the ASCII code of 'A' is 65.
XLate() can also take an address of a byte array of 256 characters. This provides a way to use a string as a replacement table. See the example.
GFA-BASIC 32 extends the XLate function by using a string array rather than an integer array which only contains one character value. By using a 256 elements string array each character in a$ can be replaced by an entire string, instead of only one character. See example 2.
Local a$, b$ , i%
For i% = 0 To 255 ' Create a table
b$ = Chr$(i%)
If b$ = Upper$(b$)
b$ = Lower$(b$)
Else
b$ = Upper$(b$)
EndIf
a$ = a$ + b$
Next i%
Message XLate$("Hallo World abcABCäöüÄÖÜ", V:a$)
prints: hALLO wORLD ABCabcÄÖÜäöü
Local a$, b$
InitEscape
Local i%, j%, t#
t = Timer
For i = 1 To 100
b = XLate(String(500, "This is a test äöüÄÖÜ"), htmlEscape())
Next
Print Timer - t, b
Do
Sleep
Loop Until Me Is Nothing
Sub InitEscape
Local out$, i%, c%
Global Dim htmlEscape$(0 .. 255)
For c = 0 To 255
Switch c
Case ">" : out$ = ">"
Case "<" : out$ = "<"
Case "&" : out$ = "&"
Case "ä" : out$ = "ä"
Case "Ä" : out$ = "Ä"
Case "ö" : out$ = "ö"
Case "Ö" : out$ = "Ö"
Case "ü" : out$ = "ü"
Case "Ü" : out$ = "Ü"
Case "ß" : out$ = "ß"
Case 0 To 31, 128 To :
out$ = "&#" & Dec$(c) & ";"
Default : out$ = Chr(c)
EndSelect
htmlEscape(c) = out
Next
End Sub
Xlate$(a$, m%()) corresponds to
For i% = 1 To Len(a$)
Mid$(a$, i%) = Chr(m%(Asc(Mid$(a$, i%, 1))))
Next i%
Upper$(), Lower$(), UCase$(), LCase$()
{Created by Sjouke Hamstra; Last updated: 25/10/2014 by James Gaite}