Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

like image 361
Dominique Makowski Avatar asked Oct 15 '25 14:10

Dominique Makowski


1 Answers

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: "; "

like image 74
DNF Avatar answered Oct 18 '25 08:10

DNF



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!