[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 329
  • Last Modified:

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!
Mike
0
thready
Asked:
thready
  • 2
  • 2
1 Solution
 
JimBrandleyCommented:
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.

Jim
0
 
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?

Mike
0
 
threadyAuthor Commented:
Oh - what do I use as begin and end record markers?
0
 
JimBrandleyCommented:
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.

Jim
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now