?
Solved

TXT Doc to Hex

Posted on 2004-09-09
12
Medium Priority
?
299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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 1700 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 300 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

764 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