Dominique Makowski
Dominique Makowski

Reputation: 1673

Julia: concat strings with separator (equivalent of R's paste)

I have an array of strings that I would like to concatenate together with a specific separator.

x = ["A", "B", "C"]

Expected results (with sep = ;):

"A; B; C"

The R's equivalent would be paste(x, sep=";")

I've tried things like string(x) but the result is not what I look for...

Upvotes: 4

Views: 2800

Answers (1)

DNF
DNF

Reputation: 12654

Use join. It is not clear if you want ";" or "; " as a separator.

julia> x = ["A", "B", "C"]
3-element Array{String,1}:
 "A"
 "B"
 "C"

julia> join(x, ';')
"A;B;C"

julia> join(x, "; ")
"A; B; C"

If you just want ; then just use a character ';'as a separator, if you also want the space, you need to use a string: "; "

Upvotes: 11

Related Questions