I can't quite understand the difference between routine 1 and routine 2
Both search and replace a substring within a file
One acts by working on bytes, the other transforms into a string and uses Replace
Are they usable with the same effectiveness?
What are the pros and cons of both?
Both search and replace a substring within a file
One acts by working on bytes, the other transforms into a string and uses Replace
Are they usable with the same effectiveness?
What are the pros and cons of both?
B4X:
' ROUTINE 1
Dim bb As B4XBytesBuilder
bb.Initialize
bb.Append(File.ReadBytes("", nome_file_completo))
SingleReplace(bb, data_da_cercare.GetBytes("ascii"), data_da_impostare_stringa.GetBytes("ascii"))
File.WriteBytes("", nome_file_destinazione, bb.ToArray)
' ROUTINE 2
Dim st As String
Dim by() As Byte= File.ReadBytes("",nome_file_completo)
st=BytesToString(by,0,by.Length,"ASCII")
st=st.Replace(data_da_cercare,data_da_impostare_stringa)
by= st.GetBytes("ASCII")
File.WriteBytes("",nome_file_destinazione,by)
Private Sub SingleReplace(bb As B4XBytesBuilder, SearchFor() As Byte, ReplaceWith() As Byte)
Dim i As Int = bb.IndexOf(SearchFor)
If i > -1 Then
bb.Remove(i, i + SearchFor.Length)
bb.Insert(i, ReplaceWith)
End If
End Sub