I would probably use map and join, but you could just as easily use foreach and concatenation. Either way you can use
for escaping. Which part are you having trouble with? Can you show us what you've tried so far? We could probably give you better, more specific help if you ask a more specific question.
Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. Why, I've got so much sanity it's driving me crazy.