LTRIM$ and RTRIM$ in Eu
The following are two rather trivial functions which I use often, so
they may be of use to other Euphorians too. They are Eu-equivalents of
the QBasic functions LTRIM$ and RTRIM$.
RZ
--TRIM.EX:
--demonstrates how to left- and right-trim strings (remove spaces
--and tabs)
--R.J. Zydenbos, Mysore, 1998.
-- (make the two functions global if you want to use them in
-- an include file)
sequence a
function ltrim(sequence a)
integer i, x, c
i = length(a)
x = 1
while x<=i do
c = a[x]
if not (c=' ' or c=9) then
exit
else
x = x+1
end if
end while
a = a[x..i]
return a
end function
function rtrim(sequence a)
integer i, c, x
i = length(a)
x = i-1
while x>1 do
c = a[x]
if not (c=' ' or c=9) then
exit
else
x = x-1
end if
end while
if x>0 then
a = a[1..x]
return a
else
return {}
end if
end function
--demo:
puts(1,"Schrijf wat: ") --type something on your keyboard
a = gets(0)
puts(1,"\n")
a = a[1..length(a)-1]
printf(1,"De invoer is: |%s|\n",{a})
a = ltrim(a)
printf(1,"En na ltrim is het: |%s|\n",{a})
a = rtrim(a)
printf(1,"En na rtrim is het: |%s|\n",{a})
|
Not Categorized, Please Help
|
|