Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Help debugging malformed data file using C#

Posted on 2005-04-13
Medium Priority
Last Modified: 2010-04-16
I have been tasked with reading in a data file from a TCP/IP stream of data.

The data coming in follows a schema based on WITS (Wellsite Information Transfer Standard, website:  http://www.witsml.org/)

The data coming in follows this general format:

XX - the record type
XX - the item type
XXXX - the data

XX - the record type
XX - the item type
XXXX - the data


Each record starts with a "&&" to delimit the beginning of the record, and a "!!" to delimit the end of the record

For the most part.......the C# code I have written seems to handle this format just fine....and 9 times out of ten the record reads in just fine.

During my testing......I have run into a problem though.

For some reason my READ-IN of the data is being STOPPED.  I am speculating that it is due to this weird "special character" that I can see in the file (when I open the file in Notepad).  The character is like a BOX.....which as I understand it....is what is displayed by the font when it does not have the ability to represent the character.

I have posted online an excerpt of the file.....hoping that the special character will SHOW UP in Notepad when whomever helps me with this problem opens the file.

I am wanting to know.....what is this character?

My other related question....and probably more important is.......how can I clear the file of ALL NON alpha numeric characters?  The only characters I want to include are Aa thru Zz, 0 thru 9, .  (period), & (ampersand) and ! (exclamation mark).  All other characters can be cleaned away.

//File excerpt.....


!!   <-----------the special "box" character is before the two !! characters

Here is the file itself.....the actual file is BIG...2 MB.   This is just a small bit of that file...enough to show the special character (I hope):

Question by:Tom Knowlton
LVL 21

Accepted Solution

Yurich earned 2000 total points
ID: 13777413
hello again,
there can be again than one solution but since your prefer using regular expressions, here it is:

Regex myRegex = new Regex( "[^A-Za-z0-9.!|&]" );
string input = GetYourInput();
string input = myRegex.Replace( input, "" );

you can use \d and \w but since different "flavours" of regex engines can interprate \w differently, i'd stick to using streight and simple way given above.


p.s. &#9786; is most likely either carriage return or new line...

Author Comment

by:Tom Knowlton
ID: 13777430
Thanks for the RegEx!!!


The problem actually turned out to be further along in the data stream than I originally thought.

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month14 days, left to enroll

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question