Android Question How to manipulate binaries of files?

aironium

Member
To put it simply, i am trying to replace a certain character in a non-text file (to be specific, a zip file, for a certain experimental project). The goal is to automate something that can be done in a hex editor.

In python, there is something like "data.replace(b'^', b'/') [data is just the file variable]", but I am not sure which is a counterpart for B4A.
 

epiCode

Active Member
Licensed User
B4X:
Dim s As String = "some text"
s = s.Replace("o", "a")
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You cannot treat non-text data as text.

B4XBytesBuilder (B4XCollections) can be useful for such tasks though for a single byte you can do something simpler:
B4X:
Dim data() As Byte = File.ReadBytes(...)
For i = 0 To b.Length - 1
 if Bit.And(0xff, data(i)) = 0x32 Then data(i) = 0x64 'the and is required if the value > 127 because bytes are signed
 Next
File.WriteBytes(...)
 
Upvote 0

aironium

Member
So this following code will comb up every byte and replace matches?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…