3
$\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$
8
$\begingroup$

Try this:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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