Encode strings using escape sequences