4
$\begingroup$

I have two strings, e.g., s1="A|P|Q|Z" and s2="r|ss|t|yy", where "|" is meant to be a separator. I would like to get the result as another string s=Ar|Pss|Qt|Zyy by joining the corresponding parts of the two strings s1 and s2 as indicated by the separators. What would be a simple way to do this?

$\endgroup$

1 Answer 1

9
$\begingroup$

Try this:

StringSplit[{s1, s2}, "|"] // Transpose // StringRiffle[#, "|", ""] &
$\endgroup$
1
  • $\begingroup$ Clean and elegant (+1). $\endgroup$ Apr 9, 2019 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.