0

I would like to take a string like "Bob[TAB]John[TAB]Harry "The Hammer" Jones" and "backslash" encode the string as such:

"Bob\tJohn\tHarry \"The Hammer\" Jones"

So I can read/write single line quoted values to file without the usual suspects like ESC, TAB, newline messing it up but still stored in the string.

a) Is there a "standard" way to do this instead or re-inventing the wheel? b) What "word" am I looking for that describes what I want to do? I feel like this should certainly be a "dup" but I don't know the right term if this is the case. For a URL, this would be URLEncode/Decode, but what is the word for "backslash encode special characters in C"?

B. Nadolson
  • 2,988
  • 2
  • 20
  • 27
  • 1
    See http://stackoverflow.com/questions/2725385/standard-c-library-for-escaping-a-string – wich Mar 13 '13 at 07:06
  • There's really no nice way to do this, besides going through the string and manually translate the special characters. – Some programmer dude Mar 13 '13 at 07:07
  • If I understand correctly, you should be looking for an equivalent of `JSON.stringify` specificly for C strings. – Alvin Wong Mar 13 '13 at 07:08
  • Yeah, "stringify" equilivalent sounds about right. That other thread provides a couple of ideas, but seems clear "roll your own" is more or less what I'll need to do. Thanks all. – B. Nadolson Mar 13 '13 at 08:32
  • This question is a dup and should be closed. If that is something I should do myself, I'm not sure how to do it. – B. Nadolson Mar 13 '13 at 08:34

0 Answers0