Splitting string into array of substrings in Julia – split() and rsplit() Method
The split()
is an inbuilt function in julia which is used to split a specified string into an array of substrings on occurrences of the specified delimiter(s).
Syntax:
split(str::AbstractString, dlm; limit::Integer, keepempty::Bool)
or
split(str::AbstractString; limit::Integer, keepempty::Bool)
Parameters:
Returns: It returns an array of substrings of the specified string.
Example:
Println(split( "Gee.ks" , "." ))
Println(split( "Geeks, for, Geeks" , ", " ))
Println(split( "GFG-gfg" , "-" , limit = 1 ))
Println(split( "GFG-gfg" , "-" , limit = 2 ))
|
Output:
String rsplit() method
rsplit()
method works exactly like split()
method but starting from the end of the string.
Syntax:
rsplit(s::AbstractString; limit::Integer, keepempty::Bool)
or
rsplit(s::AbstractString, chars; limit::Integer, keepempty::Bool)
Parameters:
Returns: It returns an array of substrings of the specified string.
Example:
Println(rsplit( "Gee.ks" , "." ))
Println(rsplit( "Geeks, for, Geeks" , ", " ))
Println(rsplit( "GFG-gfg" , "-" ; limit = 1 ))
Println(rsplit( "GFG-gfg" , "-" ; limit = 2 ))
Println(rsplit( "G-F-G-g-f-g" , "-" ; limit = 4 ))
|
Output:
Last Updated :
26 Mar, 2020
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...