Hi,

let's say I have a text file, where I want to remove all the 13,10 in. How to remove them? by just overwriting them with zeroes? doesn't that take 2 bytes every time?

NOP
Posted on 2002-01-16 13:37:59 by NOP-erator
copy until you find data you want to skip, skip, and continue until
you reach end of file. That's why you want to try to avoid removing
data from the middle of files, especially large ones :tongue: .
Posted on 2002-01-16 13:54:44 by f0dder
here is the lame (and slow) algorithm :



[1]. open file
[2]. read file in bfBuffer
[3]. esi=bfBuffer
edi=bfBuffer
ecx=len(file)
[4].
loop: test ecx,ecx
jz _done
dec ecx

lodsb

cmp al,13
jz loop
cmp al,10
jz loop

stosb
jmp loop

_done: sub edi,bfBuffer
[5]. writefile (size of new file is edi)
[6]. [optional, but recommended] take a coffe, trash the algorithm, write a faster one, read the handbook of applied cryptography
Posted on 2002-01-16 13:58:41 by roy
You may look at the Trim sources from M32lib...
It may be very instructive about that, I think...
Posted on 2002-01-16 13:59:46 by JCP
ok, thanks!
Posted on 2002-01-16 14:07:56 by NOP-erator
A sample to strip CRLF stuff

open file mapping. Create new file (not mapping) to hold that will
have the CRLF stripped. Do a similar loop to the one in the example
I uploaded. Instead of MessageBoxing the line, WriteFile it to the
new file. No temporary copying or NUL setting will be necessary.

The "stuff I uploaded" can be found in this thread:
http://www.asmcommunity.net/board/showthread.php?s=&postid=19529.msg19529
(or direct link)
http://www.asmcommunity.net/board/attachment.php?s=&postid=19439
Posted on 2002-01-16 14:48:52 by f0dder
Hello NOP-erator,
I think this function I made some weeks ago might help you.

Add this to your .data section:
EndOfLine db 13,10,0
EmptyString db 0

I think you know how to open a file for reading and writing, right? If you don't, let me know that I will give you an example.

Use it like this:
invoke ReplaceString, FileHandle, ADDR EndOfLine, ADDR EmptyString

If you replace the SubString for a bigger NewSubString, you have to make sure that the SourceString is big enough.

-------------------------------

ReplaceString proc SourceString:DWORD, SubString:DWORD, NewSubString:DWORD
LOCAL NewLenSourceString:DWORD
LOCAL LenSourceString:DWORD
LOCAL LenSubString:DWORD
LOCAL LenNewSubString:DWORD
LOCAL esi1:DWORD
LOCAL movecount:DWORD
LOCAL movemode:DWORD

cld
pushad

mov esi, SourceString
mov edi, SourceString
mov ebx, SubString
mov edx, NewSubString

invoke lstrlen, SourceString
mov LenSourceString, eax
invoke lstrlen, SubString
mov LenSubString, eax
invoke lstrlen, NewSubString
mov LenNewSubString, eax
.IF eax>LenSubString
mov movemode, 1
.ELSE
mov movemode, 0
.ENDIF

compare1:
mov ah,
compare1loop:
mov al,
inc esi
cmp al, 0
je theend
cmp al, ah
je compare2
jmp compare1loop

compare2:
dec esi
mov esi1, esi
compare2loop:
mov al,
inc esi
mov ah,
inc ebx
cmp ah, 0
je found
cmp al, ah
jne backtocompare1
jmp compare2loop

backtocompare1:
mov ebx, SubString
mov esi, esi1
inc esi
jmp compare1

found:
cmp movemode, 1
je found1
mov esi, esi1
copyloop0:
mov al,
inc edx
cmp al, 0
je copydone0
mov , al
inc esi
jmp copyloop0
copydone0:
xor eax, eax
xor ecx, ecx
mov ecx, LenSubString
sub ecx, LenNewSubString
mov eax, LenSourceString
sub eax, ecx
mov NewLenSourceString, eax
mov edi, esi
mov esi1, esi
add esi, ecx
moveloop0:
mov al,
inc esi
mov , al
inc edi
cmp al, 0
je backtocompare3
jmp moveloop0

found1:
xor eax, eax
xor ecx, ecx
mov ecx, LenSubString
sub ecx, LenNewSubString
mov eax, LenSourceString
sub eax, ecx
mov NewLenSourceString, eax
mov esi, SourceString
add esi, LenSourceString
add edi, NewLenSourceString
xor eax, eax
xor ecx, ecx
mov eax, esi1
add eax, LenSubString
mov ecx, esi
sub ecx, eax
add ecx, 1
;invoke wsprintf, ADDR strpos, ADDR fmtpos, ecx
;invoke MessageBox, 0, ADDR strpos, ADDR strpos, MB_OK
mov movecount, 0
moveloop:
mov al,
dec esi
mov , al
dec edi
inc movecount
cmp ecx, movecount
je copynewsubstr
jmp moveloop

copynewsubstr:
mov esi, esi1
copyloop:
mov al,
inc edx
cmp al, 0
je backtocompare2
mov , al
inc esi
jmp copyloop

backtocompare3:
mov esi, esi1
backtocompare2:
mov edi, SourceString
mov ebx, SubString
mov edx, NewSubString
mov eax, NewLenSourceString
mov LenSourceString, eax
jmp compare1

theend:
popad
ret
ReplaceString endp

-------------------------------

I hope this helps you.
Let me know if it worked.
I haven't had any problems with this function yet.
If anyone finds a bug or knows a way to optimize it, please let me know.

PS: This is my first post to help someone instead of asking something! :) :) :)
Posted on 2002-01-16 15:16:17 by dilau
That seems like a lot of code just for search and replace.
Posted on 2002-01-16 15:29:46 by rdaneel