# Insert a symbol include first and last position [closed]

Assume we have a list

list = {"a", "b", "c", "d", "e", "f"}


Then use this code:

StringRiffle[list,"*"]


But "*a*b*c*d*e*f*" is expected.So we should

"*" <> StringRiffle[list,"*"] <> "*"


Have a terse method do this?

-

## closed as off-topic by chuy, blochwave, Edmund, Jens, ilianMar 30 at 17:24

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – chuy, blochwave, Edmund, Jens, ilian
If this question can be reworded to fit the rules in the help center, please edit the question.

StringRiffle can also take strings to prepend and append to the result if you supply three delimiters instead of one. It's not that much terser though:

StringRiffle[list, {"*", "*", "*"}]


Of course you could remove the duplication of the strings with

StringRiffle[list, ConstantArray["*", 3]]


if you like.

For the sake of completeness, the order of the three strings in the list is {prefix, infix, suffix}, e.g.

StringRiffle[list, {"<", "*", ">"}]
(* "<a*b*c*d*e*f>" *)


Alternatively, if you always want to insert some string before/after every character (that is, if the strings in list will never contain two or more characters), you can also use StringReplace:

StringReplace["abcdef", "" -> "*"]
(* "*a*b*c*d*e*f*" *)

-
Very good solution.Cost my some time to research... – yode Mar 23 at 15:33
A workaround come to my mind.StringReplace[StringJoin@list,RegularExpression["\\B|\\b"]->"*"] – yode Mar 23 at 15:46
@yode you can have that more easily with StringReplace["adefgh12c34", "" -> "*"] but of course a lot less flexible since StringRiffle's first list may contain strings that are longer than a single character. I'll add this though if it's useful to you. – Martin Büttner Mar 23 at 15:48
You help me once again.. – yode Mar 23 at 15:49