Solved

Converting a binary text file to ASCII

Posted on 2006-06-29
11
333 Views
Last Modified: 2011-04-14
Hi there,

I am have successfully coded a ftp file transfer of METAR information from the NOAA server.  The information is in the format of a text file as follows:

2006/06/29 23:54
KRSP 292354Z AUTO 29007KT 260V340 10SM FEW080 21/14 A3005 RMK AO2 SLP171 T02060144 10261 20206 55002 $

2006/06/29 23:45
K47A 292345Z AUTO 00000KT 10SM CLR 28/12 A3011 RMK AO2

2006/06/29 23:45
KGTR 292345Z 01006KT 10SM CLR 33/14 A3006

2006/06/29 23:45
KCJR 292345Z AUTO 00000KT 10SM CLR 25/19 A3001 RMK AO2

Unfortunately when I've downloaded it it has not come down in ASCII format and so the file now loads, in Notepad, as follows:

2006/06/29 23:54KRSP 292354Z AUTO 29007KT 260V340 10SM FEW080 21/14 A3005 RMK AO2 SLP171 T02060144 10261 20206 55002 $2006/06/29 23:45K47A 292345Z AUTO 00000KT 10SM CLR 28/12 A3011 RMK AO22006/06/29 23:45KGTR 292345Z 01006KT 10SM CLR 33/14 A30062006/06/29 23:45KCJR 292345Z AUTO 00000KT 10SM CLR 25/19 A3001 RMK AO2

I need an easy way to get this file back to the format that it should be in with the correct spaces between the lines.   Any ideas please?  I am programming in Visual Basic .net 2005.

--
Ady
0
Comment
Question by:Ady Foot
  • 5
  • 3
  • 3
11 Comments
 
LVL 30

Expert Comment

by:callrs
ID: 17015065
Try metapad http://www.liquidninja.com/metapad/
It automatically deletes NUL characters. If file has other binary characters & so still won't show right, let me know.
0
 
LVL 16

Author Comment

by:Ady Foot
ID: 17015083
Yes - the issue is with carriage return line feeds.  That is to say, as I copied and pasted, that line spacings are the only things missing from my downloaded file.  I think I somehow need to open the file, replace the binary characters with ascii ones, and rewrite to file.

Any further ideas?
0
 
LVL 16

Author Comment

by:Ady Foot
ID: 17015084
Also - whatever needs to be done to the file to get it in the right format needs to be done programatically.
0
 
LVL 30

Expert Comment

by:callrs
ID: 17015091
>>It automatically deletes NUL characters
I meant it replaces them with returns

http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=1646&lngWId=8     ASCII to BINARY and visa-versa - PHP
References this tool:
http://nickciske.com/tools/binary.php     NickCiske.com | Binary- it's digitalicious!
Try that...
0
 
LVL 16

Author Comment

by:Ady Foot
ID: 17015095
Yeah - thanks but I need something in VB.net 2005 to do this.  Thanks for your help anyway though.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 30

Expert Comment

by:callrs
ID: 17015101
Disregard the last two links. IT's totally different.
Here's another way: just write a simple program to analyze the file & convert the squares to returns.
0
 
LVL 30

Expert Comment

by:callrs
ID: 17015116
See my example at
http://www.experts-exchange.com/Miscellaneous/Q_21857442.html     Miscellaneous: A little spacy

The template & program is all there & working. All you need to do is open your file in a HEX editor, and see which ASCII codes need to be replaced. Then make a slight change to my VS C++ program & you're done. : )
0
 
LVL 22

Accepted Solution

by:
cookre earned 500 total points
ID: 17015166
I believe the NOAA FTP data uses a single LF character as its line break instead of the CR/LF that we're used to.

Regardless, .NET can deal with that if you get the response as a stream file then do ReadLines().

I know this isn't VB, but it's something I did a few months back and the conversion to VB should be easy.
(I'm presuming they haven't changed their formatting in the past 6 months)


// Get the observations
string URI="ftp://weather.noaa.gov/data/observations/metar/decoded/"+Stations[idx-1,2]+".TXT";
FtpWebRequest  ftpreq  = (FtpWebRequest)  WebRequest.Create(URI);
 FtpWebResponse ftpresp = (FtpWebResponse) ftpreq.GetResponse();
Stream         fsobs   =                  ftpresp.GetResponseStream();

StreamReader srobs=new StreamReader(fsobs);
string obs="";
for (int obsidx=0; obsidx<11; obsidx++)
    {
    obs=srobs.ReadLine();
    ...
0
 
LVL 22

Expert Comment

by:cookre
ID: 17015217
And yes, I was getting mine from DECODED (hence, my reading up to 11 lines)  and yours, I presume, is from CYCLES, but the idea is the same.
0
 
LVL 30

Expert Comment

by:callrs
ID: 17015379
If it's simply a case of CRLF being replaced with LF, then metapad can convert that instantly!

In Metapad:  Options -> Settings -> Advanced > Default file format ->

Shows choice of: DOS Text, UNIX Text, Unicode, Unicode BE

Simply change a setting & reload your file.
0
 
LVL 22

Expert Comment

by:cookre
ID: 17015423
The point here is why bother with a separate conversion when .NET can handle it with a GetResponseStream() and ReadLine()?

Shoot, even good ole straight C could deal with it with a simple t-mode fopen().
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now