reading strings
- Posted by Hayden McKay <hmck1 at dodo.com.au> Sep 05, 2006
- 555 views
just wanted to share a small routine for reading strings. I use it to load large strings (no longer than 256 bytes) into euphoria. nb. probably not very fast for smaller type strings. you could change the 'TERMINMATOR' and 'MAXLENGTH' constants to suit your application
--==============================================-- constant -- TERMINATOR = 0, -- the string terminator MAXLENGTH = 256 -- maximum string length -------------------------------------------------- -- returns sequence as a string from memory/device global function string(atom lp) sequence chunk integer loc chunk = peek({lp, MAXLENGTH}) loc = find(TERMINATOR, chunk) if loc then chunk = chunk[1..(loc-1)] end if return chunk end function