How to link the elements of array into a string

x=[“j”,“u”,“l”,“i”,“a”]

such as: string?(x) into “julia”

Hi there,

the function you are looking for is called join.

julia> x=["j","u","l","i","a"]
5-element Array{String,1}:
 "j"
 "u"
 "l"
 "i"
 "a"

julia> join(x)
"julia"

Alternatively, string(x...) and reduce(*,x) work as well.

3 Likes

There is also join:

help?> join(x)
  join([io::IO,] strings, delim, [last])

  Join an array of strings into a single string, inserting the given
  delimiter between adjacent strings. If last is given, it will be
  used instead of delim between the last two strings. If io is
  given, the result is written to io rather than returned as as
  a String.

  Examples
  ≡≡≡≡≡≡≡≡≡≡

  julia> join(["apples", "bananas", "pineapples"], ", ", " and ")
  "apples, bananas and pineapples"


julia> join(["j", "u", "l", "i", "a"])
"julia"
4 Likes

Sorry, @fredrikekre I updated my post to include join before you posted yours :slight_smile:

BTW, for better readability use backticks ` short code goes here ` or triple backticks ``` longer codeblock goes here ``` to enable syntax highlighting etc. for you code.

image

2 Likes

You need to interpolate global variables with $ when benchmarking with BenchmarkTooks.jl

2 Likes

image

1 Like

An extra use case of join(x) over the use of the splat operator for the string concatenation is that join(x,',') can also let you include a delimiter (separator)

1 Like