Solved

TXT Doc to Hex

Posted on 2004-09-09
12
291 Views
Last Modified: 2010-04-23
Experts

I need to find some hext values 00 in a text file and replace it with 20 (vb.net windows app)

I have tried the simple


    Dim fileRead As New System.IO.StreamReader(DataFileLocation)
    rdLine = fileRead.ReadToEnd
    rdLine = Replace(rdLine, hex("00"), hex("20"))
    fileRead.Close()

    Dim fileWrite As New IO.StreamWriter(DataFileLocation)
    fileWrite.Write(rdLine)
    fileWrite.Close()

but this just replaced the number 0 with the number 14.

Please Help!

Ta


Matt
0
Comment
Question by:cafferm
  • 5
  • 5
  • 2
12 Comments
 
LVL 19

Expert Comment

by:drichards
ID: 12023679
Just remove the 'hex(..)' and leave the "00" and "20".  This is very dangerous if the hex values are one long string as you might erroneously turn "1001" into "1201".

Also, you can do:

    rdLine = fileRead.ReadToEnd
    rdLine.Replace("00", "20")

which is a little cleaner.
0
 
LVL 10

Expert Comment

by:prakash_prk
ID: 12023692

can you post your sample text file

regards
prakash
0
 

Author Comment

by:cafferm
ID: 12023805
The file is actually as text

some sample lines below

BAVEITMM171BANCA POPOLARE FRULADRIA SPA       (EX BANCO AMBROSIANO VENETO)      
BAVEITMM172BANCA POPOLARE FRIULADRIA S.P.A.   (EX BANCO AMBROSIANO VENETO)      
BAVEITMM173BANCA POPOLARE FRIULADRIA SPA      EX BANCO AMBROSIANO VENETO)        
BAVEITMM174BANCA POPOLARE FRIULADRIA SPA      (EX BANCO AMBROSIANO VENETO)      
BAVEITMM175BANCA POPOLARE FRIULADRIA SPA      (EX BANCO AMBROSIANO VENETO)      
BAVEITMM176BANCA POPOLARE FRIULADRIA SPA      (EX BANCO AMBROSIANO VENETO )      
BAVEITMM179BANCA POPOLARE FRIULADRIA SPA      (EX BANCO AMBROSIANO VENETO)      
BAVEITMM203BANCA POPOLARE FRIULADRIA SPA      (EX BANCO AMBROSIANO VENETO)      
BAVEITMM601BANCA POPOLARE FRIULADRIA SPA      (EX BANCO AMBROSIANO VENETO)      
BAVEITMM602BANCA POPOLARE FRIULADRIA SPA      (EX BANCO AMBROSIANO VENETO)      
BAVEITMM603BANCA POPOLARE FRIULADRIA SPA      (EX BANCO AMBROSIANO VENETO)      
BAVEITMM604BANCA POPOLARE FRIULADRIA SPA      (EX BANCO AMBROSIANO VENETO)      
BAVEITMM605BANCA POPOLARE FRIULADRIA SPA      (EX BANCO AMBROSIANO VENETO)      

So i need to convert this to hex then replace the values and convert back to text

Thanks

Matt
0
 
LVL 19

Expert Comment

by:drichards
ID: 12023826
>> So i need to convert this to hex then replace the values and convert back to text

Why?  Can't you just replace the text or do you need the numeric values for something?
0
 

Author Comment

by:cafferm
ID: 12023839
I need the numeric values.
0
 
LVL 19

Expert Comment

by:drichards
ID: 12023841
This does not seem to be a very good test file as there are no "00" in it, which is what you said you wanted to replace.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:cafferm
ID: 12023846
Here;s the Hex as viewed in ultra edit (for some of it anyway

00043650h: 29 20 20 20 20 00 00 20 0D 0A 42 41 56 45 49 54 ; )    .. ..BAVEIT
00043660h: 4D 4D 31 37 32 42 41 4E 43 41 20 50 4F 50 4F 4C ; MM172BANCA POPOL
00043670h: 41 52 45 20 46 52 49 55 4C 41 44 52 49 41 20 53 ; ARE FRIULADRIA S
00043680h: 2E 50 2E 41 2E 20 20 20 28 45 58 20 42 41 4E 43 ; .P.A.   (EX BANC
00043690h: 4F 20 41 4D 42 52 4F 53 49 41 4E 4F 20 56 45 4E ; O AMBROSIANO VEN
000436a0h: 45 54 4F 29 20 20 20 20 20 20 20 0D 0A 42 41 56 ; ETO)       ..BAV
000436b0h: 45 49 54 4D 4D 31 37 33 42 41 4E 43 41 20 50 4F ; EITMM173BANCA PO
000436c0h: 50 4F 4C 41 52 45 20 46 52 49 55 4C 41 44 52 49 ; POLARE FRIULADRI
000436d0h: 41 20 53 50 41 20 20 20 20 00 00 45 58 20 42 41 ; A SPA    ..EX BA
000436e0h: 4E 43 4F 20 41 4D 42 52 4F 53 49 41 4E 4F 20 56 ; NCO AMBROSIANO V
000436f0h: 45 4E 45 54 4F 29 20 20 20 20 20 20 20 20 0D 0A ; ENETO)        ..



0
 
LVL 19

Expert Comment

by:drichards
ID: 12023928
Oh, so you're just replacing null characters with spaces.  Hang on, I'll give you the code for that.
0
 

Author Comment

by:cafferm
ID: 12023987
thats right...thanks
0
 
LVL 19

Accepted Solution

by:
drichards earned 425 total points
ID: 12023992
       Dim sr As System.IO.StreamReader = New System.IO.StreamReader(DataFileLocation)
        Dim f As String = sr.ReadToEnd()
        sr.Close()
        Dim f1 As String = f.Replace(ChrW(0), " "c)
        Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter(DataFileLocation)
        sw.Write(f1)
        sw.Close()
0
 
LVL 10

Assisted Solution

by:prakash_prk
prakash_prk earned 75 total points
ID: 12024012
try this
  Dim fileRead As New System.IO.StreamReader(DataFileLocation)
    rdLine = fileRead.ReadToEnd
    rdLine = Replace(rdLine, chr(0),chr(20))
    fileRead.Close()

    Dim fileWrite As New IO.StreamWriter(DataFileLocation)
    fileWrite.Write(rdLine)
    fileWrite.Close()
0
 

Author Comment

by:cafferm
ID: 12024069
FANTASTIC

THANKS VERY MUCH! i have been trying to solve this for ages..EE Comes to the rescue yet again

drichards - Thanks very much

Prakash - just pipped at the post
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

17 Experts available now in Live!

Get 1:1 Help Now