SUBSTITUTE hex chr with other ...

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

SUBSTITUTE hex chr with other ...

Post by sal21 »

I loop a txt file with the tipical

free file...#1 ecc....

in the string are hex cahrcter 00 (see image).

Is possible to intecept in the string and replace with space chr? :sad: :scratch: :scratch:

tks.
You do not have the required permissions to view the files attached to this post.

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: SUBSTITUITE hex chr with other ...

Post by HansV »

Say you have a variable MyString that you use to read data from the file. You can then use

MyString = Replace(MyString, Chr(0), " ")
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: SUBSTITUITE hex chr with other ...

Post by sal21 »

HansV wrote:Say you have a variable MyString that you use to read data from the file. You can then use

MyString = Replace(MyString, Chr(0), " ")
hummmm...

the image is refered to a Hex editor, not is the line in question :scratch:

in my case 20 is a space and the . is 00 all both character in Hex
Last edited by sal21 on 13 Dec 2011, 15:50, edited 1 time in total.

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: SUBSTITUITE hex chr with other ...

Post by HansV »

How do you read the line?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: SUBSTITUITE hex chr with other ...

Post by sal21 »

HansV wrote:How do you read the line?
for test i use a Hex editor....

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: SUBSTITUITE hex chr with other ...

Post by HansV »

Yes, I understand, but how do you read the line in VBA?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: SUBSTITUITE hex chr with other ...

Post by sal21 »

HansV wrote:Yes, I understand, but how do you read the line in VBA?
sorry me.... :grin:

yes in vba for excel for first test and in official project with vb6 classic.

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: SUBSTITUITE hex chr with other ...

Post by HansV »

Please, can you show us the bit of code that you use to read the string?
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4355
Joined: 26 Apr 2010, 17:36

Re: SUBSTITUITE hex chr with other ...

Post by sal21 »

HansV wrote:Please, can you show us the bit of code that you use to read the string?
Sub LEGGI()

Dim sFileText As String
Dim iFileNo As Integer

iFileNo = FreeFile
Open "C:\TEMP\mytestfile.txt" For Input As #iFileNo
Do While Not EOF(iFileNo)
Input #iFileNo, sFileText
Loop
Close #iFileNo

End Sub

User avatar
HansV
Administrator
Posts: 78488
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: SUBSTITUTE hex chr with other ...

Post by HansV »

Sal, the text file that you sent me doesn't contain Chr(0) (except for the very last character):
S008.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans