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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Julia program to illustrate 
# the use of String split() method
   
# Splitting of the specified strings
Println(split("Gee.ks", "."))
Println(split("Geeks, for, Geeks", ", "))
Println(split("GFG-gfg", "-", limit = 1))
Println(split("GFG-gfg", "-", limit = 2))

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Julia program to illustrate 
# the use of String rsplit() method
   
# Splitting of the specified strings
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))

chevron_right


Output:




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.