escaping values in import/export setting

Hi Experts,
I am writing out a tab delimited file of records (1 record per line).  My data sometimes contains tabs and CRLF pairs.  How do I escape these items correctly and how do I unescape them?

Thanks for your help!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

It would depend on what's in the rest of the content of any field. If each is composed of simple ASCII characters in the range 0 to 0x7F, then you can search for 0x09, 0x0A or 0x0D and OR that character with 0x80 to set the high bit. Then when you read them back in, AND with 0x7F to mask out the high bits.

If your fields can contain anything in the range 0 - 0xFF, then a different strategy will be required.

threadyAuthor Commented:
Hi Jim,

I do have accents on certain characters as well...  Like èéêèà      ç

I'm starting to think I should allow multiple lines and have markers for begin and end of each record.  Just one character to delimit records, namely the | (bitwise or) character.  So for each field, I escape all backslashes by doubling them all and then I replace any instances of | with a \|

Do you think this is complete?

threadyAuthor Commented:
Oh - what do I use as begin and end record markers?
You could certainly use something like that used for HTML encoding. For example:
TAB (0x09) - &HT
CR (0x0D) - &CR
LF (0x0A) - &LF

Then when you read, you can search for those strings and replace them with the ASCII codes you pulled out. It may increase file size a bit, but it's probably safer than when trying to figure out when a backslash is just a character to be left alone. You also do not need to search for new delimiters for your fields and records.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.