I have a string of bytes (data read from a binary file by LoadFile()) in which I have to replace a substring by another string. This other string, rpl, is shorter than the substring, and should be extended to the length of the substring by adding a number of null characters chr(0). E.g.:
Function SAR(s0 As String,search As String,replace As String) As String
Dim s As String=s0
var position=Instr(s,search)
While position>0
s=Mid(s,1,position-1) & replace & Mid(s,position+Len(search))
position=Instr(position+Len(replace),s,search)
Wend
SAR=s
End Function
function Pad(byval b as string,byval padme as string) as string
padme+=string(len(b)-len(padme),0)
return padme
end function
dim as string g="abcdefghifjklmno"
dim as string h="abc"
print "'";g;"'"
print "'";pad(g,h);"'"
print
print
dim as string a
for n as long=1 to 500
a+=chr(48 + rnd*9)
next
print a
a= SAR(a,"34458225334284367436945665877883915409053775627478143871602351430", _
pad("34458225334284367436945665877883915409053775627478143871602351430","HELLO"))
print
print a
sleep
Sorry...sorry...sorry... I reduced my code to a too simplified example. Your answer, badidea, showed me that I located my error in the wrong place. Of course, this is working fine, and I discovered now my error.
Thank you both, badidea & dodicat, for your helpful hints!!!