Stefan, you just need to check in your routine if the user has enetered <LF>
We actually have a routine that works:
function split_text(text,blen)
define
text varchar(10000),
blen,tlen,i integer
if blen <= 1 then
return text clipped,null -- Illegal length
end if
let tlen = length(text)
------------------------------------------------------------------
-- Do we get an EOL within our split?
------------------------------------------------------------------
for i = 1 to minint(blen + 1,tlen) step 1
if text[i,i] = "\n" then
case
when tlen = 1 return null,null
when i = 1 return null,text[i+1,tlen] -- First char is EOL
when i = tlen return text[1,i-1],null -- Last char is EOL
otherwise return text[1,i-1] clipped,text[i+1,tlen] -- Line fits
end case
end if
end for
------------------------------------------------------------------
-- Check if last split
------------------------------------------------------------------
if tlen <= blen then
return text clipped,null
end if
------------------------------------------------------------------
-- Check if we need to split words
------------------------------------------------------------------
for i = minint(blen + 1,tlen) to 1 step -1
if text[i,i] = " " then
case
when i = 1 return null,text[i+1,tlen] -- First char space
when i = tlen return text[1,i-1],null -- Last char space
otherwise return text[1,i-1] clipped,text[i+1,tlen] -- Line split
end case
end if
end for
------------------------------------------------------------------
-- We need to split within a word
------------------------------------------------------------------
return text[1,blen],text[blen+1,tlen]
end function
function minint(val1,val2)
define val1,val2 integer
case
when val1 is null return val2
when val2 is null return val1
when val1 < val2 return val1
otherwise return val2
end case
end function
split_returns null if it finished so you can use this in a loop like:
while nigsamn.aths is not null
call split_text(nigsamn.aths,76) returning rep,nigsamn.aths
if rep is not null then
call reportput(rep)
let icnt = icnt + 1
end if
end while