[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VBScript Binary Replace Function

Posted on 2007-10-06
7
Medium Priority
?
1,367 Views
Last Modified: 2013-11-30
I'm looking for some kind of function that will do a binary replace. So it needs to be the same as the regular Replace function in vbscript, but I need to be able to submit binary data. So implemented, this function would would like this:

MyNewBinaryData = BinaryReplace(MyOldBinaryData, BinaryToFind, BinaryToReplaceWith)

I've started to hack together away to accomplish what I need using MidB, but I can't seem to make it work without messing up my binary data.
0
Comment
Question by:cnxmax
  • 3
  • 3
7 Comments
 
LVL 25

Expert Comment

by:kevp75
ID: 20030201
post your code please   (we won't write it for you, but will help....)
0
 

Accepted Solution

by:
cnxmax earned 0 total points
ID: 20030880
This is what I have and it actually seems to be working. It's not full fledged replace function like I want, but it replaces the first occurrence of some binary with some other binary.

One thing I'm not sure about (for example) is why I need to add the [* 2] in my code. Just through trial and error is how I made it work.

Anyway, if I'm going to deploy this code I want to make sure it's reliable and it's a good way to get the job done. Any help would be appreciated:

=================================================

Function BinaryToString(Binary)
  Dim I, S
  For I = 1 To LenB(Binary)
    S = S & Chr(AscB(MidB(Binary, I, 1)))
  Next
  BinaryToString = S
End Function
   
Function StringToMultiByte(S)
  Dim i, MultiByte
  For i=1 To Len(S)
    MultiByte = MultiByte & ChrB(Asc(Mid(S,i,1)))
  Next
  StringToMultiByte = MultiByte
End Function

theData = SomeBinaryData 'A variable already set with the binary data.

Var_Old = StringToMultiByte("Some Old Text")
Var_New = StringToMultiByte("New Text In It's Place")
       
Var_OldPos = InStrB(theData, Var_Old) - 1
   
   
newData = MidB(theData, 1, Var_OldPos) & Var_New & MidB(theData, Var_OldPos + (LenB(Var_OldPos)*2), Len(theData) * 2)

=================================================
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 20031089
Hi, I'm not sure whether you've tried this, but have a go with the standard VBScript Replace function, and just specify vbBinaryCompare as the last parameter for the function.

http://msdn2.microsoft.com/en-us/library/238kz954.aspx

Regards,

Rob.
0
Industry Leaders: 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!

 

Author Comment

by:cnxmax
ID: 20032120
Thanks for the tip RobSampson. I have tried that and haven't been able to get it to work. The strange thing about it is that the binary compare is the default method for the replace function, which I frequently use for regular text string data. So I'm not sure what the difference is between binary compare and text compare.

I don't know for sure that the regular replace option can't be used, because with this problem there are many areas where I'm not really sure what I'm doing so there might be two things I'm doing wrong at any given attempt.

I was hoping this wasn't such an uncommon problem and that someone could just point me to  simple solution. At this point I'm still looking for a reliable binary replace
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 20032525
Looking at the functions you've got, would it be easier to convert all binary chunks into string variables, then perform the standard replace, and convert back to binary?

Or am I off track with what you're trying to achieve?

Regards,

Rob.
0
 

Author Comment

by:cnxmax
ID: 20159708
I'm not really sure what to do with this question. The only solution I have found is the one I came up with myself. It's not what I was hoping for, but it works.

Should I just accept a solution or can should this question be closed in some other  way?
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 20159753
You can post a request in the Community Support --> General zone to have this question either PAQ'ed with an answer of yours, or deleted, if you don't need it, including the link to this question.

Regards,

Rob.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Hello Friends, My friends and relatives always ask me how to delete all the various types of emails at once in our g-mail  or windows live account.  So I researched this topic to find a unique solution to this query.  Here it is for those who do …
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month20 days, 4 hours left to enroll

872 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