rsplit

rsplit(string, [chars]; limit=0, keep=true)

Similar to split, but starting from the end of the string.

Examples

  1. Split a string into an array of substrings from the end:

    julia> rsplit("Hello World", " ")
    2-element Array{SubString{String},1}:
    "Hello"
    "World"

    This example splits the string "Hello World" into an array of substrings at the space character from the end of the string.

  2. Limit the number of splits:

    julia> rsplit("a,b,c,d,e", ",", limit=2)
    3-element Array{SubString{String},1}:
    "a,b"
    "c"
    "d,e"

    It limits the number of splits to 2, resulting in an array of 3 substrings.

  3. Keep empty substrings:
    julia> rsplit("apples,oranges,,bananas", ",", keep=true)
    4-element Array{SubString{String},1}:
    "apples"
    "oranges"
    ""
    "bananas"

    It includes empty substrings in the resulting array.

Common mistake example:

julia> rsplit("Hello World", limit=2)
ERROR: MethodError: no method matching rsplit(::String; limit=2)

In this example, the rsplit function is called without specifying the separator. It's important to provide the separator as the second argument to rsplit when using the limit keyword argument.

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: