DanielX Guest
|
Posted: Mon Mar 21, 2005 5:14 am Post subject: newbie question |
|
|
I am new to basm and I ask for better code for char replacement in a string,
I would like to reduce size of code.
TIA
Daniel
procedure CharReplace2(sText,old,new:pchar); assembler;
asm
push ebx
or eax,eax //stext
jz @2
mov bl,[edx] //old
mov bh,[ecx] //new
mov ecx,[eax-4] {size of string}
@bucle:
cmp byte [eax],bl
jnz @ok
mov byte [eax],bh
@ok:
inc eax {Next letter}
loop @bucle
@2:pop ebx
end;
function CharReplace(s,oldchar,newchar : string) : string;
begin
Result:=copy(s,1,length(s));
CharReplace2(pchar(Result),pchar(oldchar),pchar(newchar));
end;
|
|