473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

ASP Binary data transformation

Hello,

I'm using ADODB.Stream to open a binary file on the server and write
it down to the browser using Response.BinaryWrite. It's working fine,
but i need to make some changes to the binary data before it is send
to the browser.

I'm trying to use REPLACE, but it's not finding a string that i know
it's in the binary file. Using InstrB i've found that the search
inside the binary data is being done in a Unicode format, but i don't
know how to make an ascii search&replace operation on binary data.

I'd greatly appreciate any help, cause i'm blocked.

thanks,
ferran
Jul 19 '05 #1
1 6265
Ferran,

Just to make sure I'm clear --- you need an ASCII file on the client,
and is the server binary also ASCII?

I think there are a couple of ways to go. If it is a text file, you
could convert to a Unicode string on the server, do your string
manipulation and then convert back. You could also save as a text
file on the server and provide a hyperlink rather than doing a binary
write.

If you really need to do a binary write, then I think you need to just
do string manipulation by using InstrB. One approach would be to get
the index of the content to replace, build a string byte by byte up to
it, add the new content and then build a string byte by byte from the
remaining content.

In VB you can do something like this:

myString = ""
For intCounter = 1 To intIndexOfReplacedContent
myString = myString & Chr(AscB(MidB(strWebFileText, intCounter,
1)))
Next

For intCounter = 1 To Len(strWebFileText)
myString = myString & Chr(AscB(MidB(strWebFileText, intCounter,
1)))
Next

For intCounter = 1 To Len(strWebFileText) -
intIndexAfterReplacedContent
myString = myString & Chr(AscB(MidB(strWebFileText, intCounter4,
1)))
Next

Then you need to call a function to convert the resulting unicode
string to ASCII. Michael Kaplan posted code to do this --- he has a

WtoA functing in a module called inCodePage. I've re-posted below,
but again this is his code, not mine.

'--------------------------------
' WToA
'
' UNICODE to ANSI conversion, via a given codepage
'--------------------------------
Public Function WToA(ByVal st As String, Optional ByVal cpg As Long =
-1, Optional lFlags As Long = 0) As String
Dim stBuffer As String
Dim cwch As Long
Dim pwz As Long
Dim pwzBuffer As Long
Dim lpUsedDefaultChar As Long

If cpg = -1 Then cpg = GetACP()
pwz = StrPtr(st)
cwch = WideCharToMultiByte(cpg, lFlags, pwz, -1, 0&, 0&, ByVal 0&,
ByVal 0&)
stBuffer = String$(cwch + 1, vbNullChar)
pwzBuffer = StrPtr(stBuffer)
cwch = WideCharToMultiByte(cpg, lFlags, pwz, -1, pwzBuffer,
Len(stBuffer), ByVal 0&, ByVal 0&)
WToA = Left$(stBuffer, cwch - 1)
End Function
---------------------------------------------------------

I haven't tested this, but something like this should work.

Hope it helps,
Mark
Hello,

I'm using ADODB.Stream to open a binary file on the server and write
it down to the browser using Response.BinaryWrite. It's working fine,
but i need to make some changes to the binary data before it is send
to the browser.

I'm trying to use REPLACE, but it's not finding a string that i know
it's in the binary file. Using InstrB i've found that the search
inside the binary data is being done in a Unicode format, but i don't
know how to make an ascii search&replace operation on binary data.

I'd greatly appreciate any help, cause i'm blocked.

thanks,
ferran

Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Maurizio Penna | last post by:
I, guys. I've embeded an image into a xml file, something like that: <display type="picture" mime="image/png" name = "mosaico6.png"> <!]> </display> Now, I want to display it with a XSL...
2
by: hipo | last post by:
Hi: I'm trying to read data from Navision 2.60 ERP with own database to a SQL Server 2000 database via ODBC. All is working except just one thing, how to filter data with a date field. I have...
103
by: Steven T. Hatton | last post by:
§27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it...
1
by: cfyam | last post by:
How can I transfer Excel data to Sql Server?
3
by: The unProfessional | last post by:
I'm having difficulty figuring out a simple way to dump unmanaged structure and/or class data to binary files. In standard C++: -------------------------- typedef struct tagS1 { DWORD dwBlah;...
26
by: Patient Guy | last post by:
Has anyone written code that successfully manipulates binary file data using Javascript? It might---and in the case of doing I/O, will---make use of browser- specific functions (ActiveX/COM with...
6
by: young_leaf | last post by:
Using STL how do I convert a variable to a binary string but with special case which for example BYTE x, i need only the first 3 bits of this byte, is that possible? to be more specific, from...
22
by: QQ | last post by:
Hi I have a unsigned char array, but I need to compress it in the bit level. for instance the array is 0x91,0x92,0x93.... I need to change it into a bit stream like 10010001 10010010 10010011...
1
by: AK | last post by:
Hello, I'm trying to create an XML digital signature over some assets listed in the XML file. It works fine until I add a pdf file in the list of assets, which throws an exception saying that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.