skipchars

skipchars(stream, predicate; linecomment::Char)

Advance the stream until before the first character for which predicate returns false. For example skipchars(stream, isspace) will skip all whitespace. If keyword argument linecomment is specified, characters from that character through the end of a line will also be skipped.

Examples

  1. Skipping whitespace in a string:

    julia> str = "   Hello, World!";
    julia> skipchars(str, isspace)
    "Hello, World!"

    This example skips all leading whitespace characters in the string str.

  2. Skip characters until a specific condition is met:

    julia> str = "123abc456";
    julia> skipchars(str, isdigit)
    "abc456"

    It skips all leading digits in the string str until the first non-digit character is encountered.

  3. Skip characters until the end of a line comment:
    julia> str = "# This is a comment\nHello, World!";
    julia> skipchars(str, isspace, linecomment='#')
    "Hello, World!"

    In this example, it skips all leading whitespace characters and characters from the line comment character (#) until the end of the line.

Common mistake example:

julia> str = "  Hello, World!";
julia> skipchars(str, isletter)
"Hello, World!"

In this example, the predicate function is set to isletter which checks if the character is a letter. However, the leading whitespace is not skipped because the predicate function does not match the spaces. To skip the whitespace, isspace should be used as the predicate function.

See Also

deserialize, eachline, eof, fd, flush, IOBuffer, ismarked, isopen, isreadonly, mark, nb_available, open, pipeline, position, read, read!, readavailable, readbytes, readbytes!, readline, redirect_stderr, redirect_stdin, reset, seek, seekend, seekstart, serialize, skip, skipchars, TextDisplay, unmark, write, writemime,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: