XTRANS() function with small test code below. It uses hash array
for better performance and supports dynamic (fields 'date', 'time')
and
static (fields 'fs01', 'fs02') translations.
I want a beer ;-)
best regards,
Przemek
proc main()
local cData, hTrans
cData := "#normal #text#, some data [#fs01#]=>(#fs02#), #date#
#time##"
hTrans := { "fs01" => "VAL-01", "fs02" => "VAL-02", ;
"date" => {||dtoc(date())}, "time"=> {||time()} }
? cData
? xtrans( cData, hTrans )
return
function xtrans( cData, hTrans )
local cText, cResult, cDelim, xValue, lNext
cResult := ""
cDelim := "#"
lNext := .f.
for each cText in hb_aTokens( cData, cDelim )
if lNext
if cText $ hTrans
xValue := hTrans[ cText ]
if valtype( xValue ) $ "BS"
xValue := eval( xValue )
endif
else
xValue := NIL
endif
if valtype( xValue ) $ "CM"
cResult += xValue
lNext := .f.
else
cResult += cDelim
cResult += cText
endif
else
cResult += cText
lNext := .t.
endif
next
return cResult