readuntil
readuntil(stream, delim)
Read a string, up to and including the given delimiter byte.
Examples
In the Julia programming language, the function readuntil(stream, delim)
is used to read a string from a stream, up to and including the given delimiter byte. It returns the string that has been read.
julia> io = IOBuffer("Hello, World! How are you?");
julia> readuntil(io, '!')
"Hello, World!"
Here are some common examples of how to use the readuntil
function:
-
Read until a specific character:
julia> io = IOBuffer("Julia is awesome!"); julia> readuntil(io, '!') "Julia is awesome!"
In this example, the function reads the string from the
IOBuffer
io
until it encounters the exclamation mark ('!'). -
Read until a newline character:
julia> io = IOBuffer("This is the first line.\nThis is the second line."); julia> readuntil(io, '\n') "This is the first line.\n"
The function reads the string from the
IOBuffer
io
until it reaches the newline character ('\n'). - Read until a specific byte value:
julia> io = IOBuffer([0x41, 0x42, 0x43, 0x44, 0x45]); julia> readuntil(io, 0x43) "ABCD"
The function reads the string from the
IOBuffer
io
until it finds the byte value 0x43 (ASCII value of 'C').
Common mistake example:
julia> io = IOBuffer("Hello, World!");
julia> readuntil(io, 'z')
ERROR: ArgumentError: delimiter not found
In this example, the delimiter 'z' is not present in the string, resulting in an ArgumentError
. Make sure that the delimiter you specify exists in the stream to avoid such errors.
See Also
ascii, base64decode, Base64DecodePipe, base64encode, Base64EncodePipe, bin, bits, bytestring, charwidth, chomp, chop, chr2ind, contains, endswith, escape_string, graphemes, ind2chr, iscntrl, istext, isupper, isvalid, join, lcfirst, lowercase, lpad, lstrip, normalize_string, num2hex, parseip, randstring, readuntil, replace, repr, rpad, rsplit, rstrip, search, searchindex, split, startswith, string, stringmime, strip, strwidth, summary, takebuf_string, ucfirst, unescape_string, uppercase, utf16, utf32, utf8, wstring,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.