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:
- str::AbstractString: Specified string.
- Dlm: Specified delimiter.
Below arguments are optional:
- limit::Integer: It is the maximum size of the result. It’s default value is zero (0).
- keepempty::Bool: It says whether the empty fields should be kept in the result or not. Its Default value is false.
Returns: It returns an array of substrings of the specified string.
Example:
# Julia program to illustrate # the use of String split() method # Splitting of the specified stringsPrintln(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:
- str::AbstractString: Specified string.
- chars: Specified characters.
Below arguments are optional:
- limit::Integer: It is the maximum size of the result. It’s default value is zero (0).
- keepempty::Bool: It says whether the empty fields should be kept in the result or not. Its Default value is false.
Returns: It returns an array of substrings of the specified string.
Example:
# Julia program to illustrate # the use of String rsplit() method # Splitting of the specified stringsPrintln(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:


Please Login to comment...