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
Solved

TXT Doc to Hex

Posted on 2004-09-09
12
295 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
VB.NET 1 28
.NET 2008 VB and C# 6 39
Calculate number of nights between two dates 5 53
Optimize the query 5 42
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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

790 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