reading strings

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

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


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

Search



Quick Links

User menu

Not signed in.

Misc Menu