Re: help!
Matt just wrote:
>I found out there are no functions for trimming white space(like LTRIM$
>and RTRIM$ in BASIC), so i tried to make one. then i found out there are
>no functions that can scan variables(like MID$ in BASIC). So, i found a
>bbbbbbbiiiiiiiggggggggg disadvantage in Euphoria.
You have to have a pretty big mouth to shout such big words...
The really big advantage of Euphoria is you can roll your own function
of this kind quite easily, and they are invariably zillion times
faster than equivalents in your beloved, crummy BASIC:
function ltrim(sequence s)
-- 'short-circuit' optimized left trim
integer c,i,len
len=length(s)
i=1
while i<=len do
c=s[i]
if c=32 then i=i+1
elsif c=10 then i=i+1
elsif c=13 then i=i+1
elsif c=9 then i=i+1
else exit end if
end while
return s[i..len]
end function
function rtrim(sequence s)
-- 'short-circuit' optimized right trim
integer c,i
i=length(s)
while i do
c=s[i]
if c=32 then i=i-1
elsif c=10 then i=i-1
elsif c=13 then i=i-1
elsif c=9 then i=i-1
else exit end if
end while
return s[1..i]
end function
function trim(sequence s)
-- trim 'white space' from both ends of string s
-- 'short-circuit' optimized
integer c,i,j,len
len=length(s)
i=1
while i<=len do
c=s[i]
if c=32 then i=i+1
elsif c=10 then i=i+1
elsif c=13 then i=i+1
elsif c=9 then i=i+1
else exit end if
end while
j=len
while j>=i do
c=s[j]
if c=32 then j=j-1
elsif c=10 then j=j-1
elsif c=13 then j=j-1
elsif c=9 then j=j-1
else exit end if
end while
return s[i..j]
end function
Enjoy. jiri
|
Not Categorized, Please Help
|
|