News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

About deleting text in text files

Started by Rainstorm, January 07, 2007, 10:27:22 PM

Previous topic - Next topic

Rainstorm

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.

Darrel

#1
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

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Darrel

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

Rainstorm

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
-


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

Rainstorm

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

Darrel

If you use the code I wrote it contains the byte count of the modified data in eax.

Regards,

Darrel

Rainstorm