Solved

TXT Doc to Hex

Posted on 2004-09-09
12
297 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 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