We help IT Professionals succeed at work.

VBScript Binary Replace Function

cnxmax asked
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.
Watch Question

post your code please   (we won't write it for you, but will help....)
Unlock this solution and get a sample of our free trial.
(No credit card required)
Most Valuable Expert 2012
Top Expert 2014

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.





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
Most Valuable Expert 2012
Top Expert 2014

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?




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?
Most Valuable Expert 2012
Top Expert 2014

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.



Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.