lstrip

lstrip(string, [chars])

Return string with any leading whitespace removed. If chars (a character, or vector or set of characters) is provided, instead remove characters contained in it.

Examples

  1. Remove leading whitespace from a string:

    julia> lstrip("   Hello, Julia!")
    "Hello, Julia!"

    This example removes leading whitespace from the string " Hello, Julia!".

  2. Remove specific characters from the beginning of a string:

    julia> lstrip("###Julia is awesome!", ['#', '!', ' '])
    "Julia is awesome!"

    It removes the characters #, !, and whitespace from the beginning of the string.

  3. Handle empty or whitespace-only strings:
    julia> lstrip(" ")
    ""

    It returns an empty string when the input string is either empty or contains only whitespace.

Common mistake example:

julia> lstrip("Julia is great!", 'J')
ERROR: MethodError: no method matching lstrip(::String, ::Char)

In this example, the second argument provided to lstrip is a character instead of an array or set of characters. To remove a specific character, it should be passed as an array or set.

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.

*Required Field
Details

Checking you are not a robot: