Image

Imagesciamachy wrote in Imagejava_dev

Brainteaser for all you programmers out there

I'm trying this thing where I have a CSV file being exported from SQL Server, and one of the fields is an XML page, so to speak. Inside this XML there may or may not be one or more commas. Now, if it weren't for that I could read it in using a BufferedReader and run it through a StringTokenizer with the delimiter set as ",", but because of the XML field's internal commas it's not that simple. How should I handle this best? The object of the program is to basically truncate any fields that exceed 256 characters, as it's to be imported into Excel later.

Don't go doing the thing for me, but if you can show me with a little pseudocode I'd be very grateful.

Addendum:

This is the format of the file, approximately:
1005,23,567.99,<XML_DATA><A_TEXT_FIELD>Here's some text, which may, or may not, contain commas.</A_TEXT_FIELD></XML_DATA>,next bit of data,some more text data,2,3,0,0


Closure:

Sorted it - pattern matching turned out to be the thing to use, definitely. Sorted it out by basically using the pattern matching to strip the XML (which the client wasn't that interested in) from the file, replacing it with "XML Stripped," to pad out the column. Thanks to those that helped.