Solved

TXT Doc to Hex

Posted on 2004-09-09
12
296 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
Independent Software Vendors: 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 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