Re: Errors in function trim() (ESL0.01)

new topic     » goto parent     » topic index » view thread      » older message » newer message

This one of the first routes I wrote when I started Euphoria a long time ago.

</eucode>
{{{

global function del_trail(object line)    -- delete trailing whitespace
 if length(line)<2 then
  return " "
 end if
    while find(line[length(line)],  " \t\n" ) do--WHITE_SPACE
	   line = line[1..length(line)-1] 
    end while
  return line
end function

global function trim(object line)
	if sequence(line) and length(line)>0 then
	    -- delete any leading whitespace
	    while find(line[1], " \t\n") do
		line = line[2..length(line)]
		if length(line) = 0 then
		    exit
		end if
	    end while
	end if
     if sequence(line) and length(line)>0 then
       -- delete trailing whitespace
       while find(line[length(line)], " \t\n") do
	     line = line[1..length(line)-1] 
       end while
     end if
    return line
end function 
</eucode>
{{{

Don Cole

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu