Re: help!
>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.
A function to scan ?
A function to trim ?
This all sounds like string specific functions to me.. in the euphoriotic
way of thinking strings do not exist.
But see here how easily, it is achieved with the general purpose sequence
manipulators:
-- 100% safe, works with any kind of sequence
-- (is not recursive.. only the upper sequence gets cut)
function ltrim (sequence s)
if not length(s) then return {} end if
while not compare (s[1],' ') do -- safer than s[1] = ' '
s = s[2..length(s)]
end while
return s
end function
-- 100% safe, works with any kind of sequence
-- (is not recursive.. only the upper sequence gets cut)
function rtrim (sequence s)
if not length(s) then return {} end if
while not compare (s[length(s)],' ') do -- safer than s[end] = ' '
s = s[1..length(s)-1]
end while
return s
end function
-- And the combination of both (again 100% safe, non-recursive)
function trim (sequence s)
return ltrim(rtrim(s))
end function
-- And this function shows how we mids () in euphoria.. off course the
euphoric way is much more cleaner than the basic way, but if you want to do
it the basic way, you could use this function --
function mids (sequence s, integer start, integer len)
return s[start..start+len]
end function
Seen the light already ?
Ralf Nieuwenhuijsen
nieuwen at xs4all.nl
|
Not Categorized, Please Help
|
|