Home > Software design >  Delimiters in split function Julia
Delimiters in split function Julia

Time:11-08

I got some issues trying to split a sentence in single substrings. Using the split function, I can't manage to use more than a delimiter. The code is:

sentence = "If you're visiting this page, you're likely here because you're searching for a random sentence"

split(sentence, "," , " " , ";")

I get this error:

LoadError: MethodError: no method matching split(::String, ::String, ::String, ::String).

I would like to get an array of single words.

CodePudding user response:

Provide a vector of Chars as the split argument (in Julia quotation " is used for String and apostrophe ' for Char):

julia> split(sentence,[' ',',',';'])
16-element Vector{SubString{String}}:
 "If"
 "you're"
 "visiting"
 "this"
 "page"
 ""
 "you're"
 "likely"
 "here"
 "because"
 "you're"
 "searching"
 "for"
 "a"
 "random"
 "sentence"
  • Related