strip

strip(string, [chars])

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

Examples

  1. Strip leading and trailing whitespace from a string:

    julia> str = "   Hello, Julia!   ";
    julia> strip(str)
    "Hello, Julia!"

    This example removes any leading and trailing whitespace from the string str.

  2. Strip specific characters from a string:

    julia> str = "###Julia###";
    julia> strip(str, '#')
    "Julia"

    It removes the specified character ('#') from both ends of the string str.

  3. Strip multiple characters from a string:
    julia> str = "!!Julia!!";
    julia> strip(str, ['!', '@'])
    "Julia"

    It removes all occurrences of the characters '!' and '@' from both ends of the string str.

Common mistake example:

julia> str = "Julia";
julia> strip(str, 'Jul')
ERROR: MethodError: no method matching strip(::String, ::String)

In this example, the chars argument is provided as a string ('Jul') instead of a character or vector/set of characters. The chars argument should be a character or collection of characters, not a string.

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: