将字符串连接到字符串向量

Geo*_*ery 7 julia

我有一个字符串向量

faces = ["bold", "ital", "code"]

3-element Vector{String}:
 "bold"
 "ital"
 "code"
Run Code Online (Sandbox Code Playgroud)

我有一个标量String

"The font face is "
Run Code Online (Sandbox Code Playgroud)

我想结合成Vector{String}

["The font face is bold", "The font face is ital", "The font face is code"]
Run Code Online (Sandbox Code Playgroud)

我可以发誓我在使用之前就这样做了$faces,但我不记得是怎么做的。


附加说明:
我正在寻找一种将向量的元素插入字符串的方法。因此,在"The font face is " .* faces适用于本示例的同时,我也在寻找将向量值放入字符串内的解决方案。一个解决方案的工作原理如下

String.("The font face is $(faces)")
Run Code Online (Sandbox Code Playgroud)

sun*_*ica 9

从你问题的最后一行来看,你可能有这样的模式:

julia> string.("The font face is ", faces)
3-element Vector{String}:
 "The font face is bold"
 "The font face is ital"
 "The font face is code"
Run Code Online (Sandbox Code Playgroud)

从语义上讲,这个.*解决方案和地图解决方案最终在做同样的事情,但也许您更喜欢这种语法。


Jaf*_*rov 6

faces = ["bold", "ital", "code"]
str = "The font face is "

map(x -> str*x, faces)
Run Code Online (Sandbox Code Playgroud)