Hi.
How do i go about deleting text in a text file ?
I know how to read/write to one.
(Also, can it be done with the fwrite function in masm ?)
I want to delete just part of the text & keep the rest.
could someone give some basic example(s) of how this is done usually .
For example if the file had
ABCDEFGHIJKLMNOPQ
& I only want to delete EFG
something like that..
Thankyou
Rainstorm.
Here is the code I put together
push ebx
push edi
push esi
mov ebx,lpDeleteString
mov edi,lpDestinationString
mov esi,lpSourceString
xor ecx,ecx
StartCheckString:
mov ah,BYTE PTR[ebx]
StartCheckString00:
cmp ah,BYTE PTR[esi+ecx]
je CheckString
WriteString:
mov al,BYTE PTR[esi+ecx]
mov BYTE PTR[edi],al
inc edi
inc ecx
WriteString00:
cmp ecx,SourceStringLengthMinusDeleteStringLengthPlusOne
jb StartCheckString00
jmp CheckStringDone00
CheckString:
xor edx,edx
CheckString00:
inc esi
inc edx
cmp edx,DeleteStringLength
je StringFound
mov al,BYTE PTR[ebx+edx]
cmp al,BYTE PTR[esi+ecx]
je CheckString00
sub esi,edx
jmp WriteString
StringFound:
sub esi,edx
add ecx,edx
jmp WriteString00
CheckStringDone:
mov al,BYTE PTR[esi+ecx]
mov BYTE PTR[edi],al
inc edi
inc ecx
CheckStringDone00:
cmp ecx,SourceStringLength
jb CheckStringDone
sub edi,lpDestinationString
mov eax,edi ;eax contains DestinationStringLength
pop esi
pop edi
pop ebx
HTH,
Darrel
Rainstorm,
You can also have a look at the procedure in the masm32 library that is designed for this task.
szRemove proc src:DWORD,dst:DWORD,remv:DWORD
It is documented in the masmlib help file.
The only real difference between the two methods is mine does not require a terminating null character at the end of any string.
Regards,
Darrel
hi,
thanks for the code example Daryl, it was helpful.
I went through the code for the szRemove function too.
I get the general idea of the technique.
So basically the whole file is rewritten/owerwritten with the data in the destination buffer.
(assuming I read the whole file into the source buffer,....i.e)
And use fseteof after the fwrite.
thanks everyonel for the replies.
Rainstorm
-
when using fwrite it doesn't matter if the destination buffer is not zero-terminated..is that right ?
- since fwrite uses the 'bytecount' input to write.
thnks
hi ,
how do i get the size of my info in the destination buffer.
when i use fwrite(hFile,buffer,bcnt) i need the bytecount of the modified data
thankyou
Rainstorm
If you use the code I wrote it contains the byte count of the modified data in eax.
Regards,
Darrel
thanks again Darrel
Rainstorm