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

x
?
Solved

Help debugging malformed data file using C#

Posted on 2005-04-13
2
Medium Priority
?
269 Views
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

ETC., ETC., ETC.


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.....

0141462
01420
0143-150.0
0144-993


!!   <-----------the special "box" character is before the two !! characters
&&
0105050411
0106074240
010813308.8
011013308.8


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):

http://www.knowltonsoftware.com/junk/sample_data.txt
0
Comment
Question by:Tom Knowlton
2 Comments
 
LVL 21

Accepted Solution

by:
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.

regards,

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

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.
0

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