split string only by the first occurrence of a delimiter
Use the limit
keyword.
For this kind of questions you can also efficiently use the inline documentation.. just type ?split
(or any other function or type) in the console to retrieve a nice explanation of the function, their arguments and often usage examples. In this case:
help?> split
search: split splitext splitdir splitpath splitdrive rsplit splice! displaysize @specialize @nospecialize
split(str::AbstractString, dlm; limit::Integer=0, keepempty::Bool=true)
split(str::AbstractString; limit::Integer=0, keepempty::Bool=false)
Split str into an array of substrings on occurrences of the delimiter(s) dlm. dlm can be any of the formats allowed by findnext's first argument (i.e. as a string, regular expression or a function), or as a single character or collection of characters.
If dlm is omitted, it defaults to isspace.
The optional keyword arguments are:
• limit: the maximum size of the result. limit=0 implies no maximum (default)
• keepempty: whether empty fields should be kept in the result. Default is false without a dlm argument, true with a dlm argument.
See also rsplit.
Examples
≡≡≡≡≡≡≡≡≡≡
julia> a = "Ma.rch"
"Ma.rch"
julia> split(a,".")
2-element Array{SubString{String},1}:
"Ma"
"rch"
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Splits an HyperRectangle into two along an axis at a given location.
The limit
keyword argument will set the maximum number of chunks in the result:
julia> split("abc.de.fg.hij.k", "."; limit=2) # split at most once
2-element Array{SubString{String},1}:
"abc"
"de.fg.hij.k"
julia> split("abc.de.fg.hij.k", "."; limit=3) # split at most twice
3-element Array{SubString{String},1}:
"abc"
"de"
"fg.hij.k"