Hi !

I want to write a function to replace a string to another in a big text:

String 1: "rrr"
String 2: "zugtr"

ttt eee rrr tttrtorui ptrzzu uzotiu rrrr rrrr rrr ieu

replace strings in the text to...

ttt eee zugtr tttrtorui ptrzzu uzotiu zugrtr zugrtr zugrt ieu

Is there out a good and fast replace funktion ??

Greetings, Nordwind64
Posted on 2002-04-18 09:47:30 by Nordwind64
You seem to be replacing rrrr (x4 r) the same as you would rrr (the string, and x3 r).
rrr -> zugtr
rrrr -> zugtr

rrrr -> zugtrr

Is this deliberate or a typo?

Posted on 2002-04-18 10:01:36 by Mirno

rrr -> zugtr
rrrr -> zugtrr

or rrrrrr -> zugtrzugtr

or rrrrr -> zugtrrr

Posted on 2002-04-18 10:07:52 by Nordwind64
future ref. use real words... :)
They're easier to follow and understand in replace functions...

saying "rrr" and "sfdgaf" takes more to follow then a simple sentence...

Posted on 2002-04-18 12:48:14 by Sliver

that were real words, in my timbuktu home language...
No, ok, sorry !

String 1 = "whenever"
String 2 = "may not have"

"emails sent to you whenever someone replies. "


"emails sent to you may not have someone replies. "

Ok ?

Greetings, Frank
Posted on 2002-04-18 13:07:20 by Nordwind64
Why search and replace when you can simply ask what your looking for first :grin:

szEmail db "emails sent to %s someone replies.",0
szWhen db "whenever",0
szNot db "may not have",0

Buffer db 256 dup(?)


.if( Flag == TRUE)
; Do whenever
invoke wsprintf, addr Buffer, addr szEmail, addr szWhen

; Do may not have
invoke wsprintf, addr Buffer, addr szEmail, addr szNot


; Show it
invoke StdOut, addr Buffer ; or however you want to use the string

Just a sugestion...
Posted on 2002-04-18 13:34:35 by NaN
Hi NaN

That was only an example, I need a complete replace funktion for two strings in a big text, but I don't know how to...

Sorry, english is not my mother language, so it could give translation problems ???

Posted on 2002-04-18 14:13:15 by Nordwind64
I will leave this one for other learned people to tackle. (I have an economics exam tomorrow, and the solution wont be all to simple (as i perceive it anyways) ).

If your still hanging come saturday, I'll help you then...

Good Luck.
Posted on 2002-04-18 14:47:24 by NaN
Searched the site for "replace" "string" and came up with this from the algor. section (There's alot that can be done in the optimization area, but the author says it works)

Replace String

I'm gonna try my hand at a more optimized version so tell me if that works...

Posted on 2002-04-18 17:52:11 by Sliver
Just my 2 cents :grin:

Use a string search algorithm then just use EM_SETSEL to select the text then use EM_REPLACESEL.

Select = StartingPointOfTheText -> StartingPointOfTheText + strlen of the first string.

Replace = StartingPointOfTheText

I don't know if this works but it's just a theory. :grin:
Posted on 2002-04-18 22:05:53 by stryker
There are a number of problems with a replace function, if the replacement is the same length or shorter, you just find the source string in the first buffer, write the replacement string at its offset, in the second buffer, step to the next character after the source and do it again until you have reached the end.

It becomes more complex when the replacement is longer than the source as you need some memory strategy to handle the extra length. What I have in mind when I have time is to use one of the boyer moore derivations that counts the number of specified patterns in a source, do the arithmetic and reallocate the extra memory needed for the second buffer and then run a replacement algo like the one mentioned above.


Posted on 2002-04-19 02:21:12 by hutch--
Hey stryker, nice to see they let you on the net in martian prison :tongue:
Posted on 2002-04-19 02:26:05 by NaN

ok, I've finished my function. It's a Dll function, here is it...
Thank you to all !


; ______________________________________________
Replace proc
; ??????????????????????????????????????????????
;Dll function: Replace (source text,
; lenght of source text,
; destinationtext,
; search-string,
; lenght of search-string,
; replace-text
; lenght of replace-text
; )

push ebp
mov ebp,esp

mov zahler,0

mov ebx, ;ebx = Pointer to the textmemory
mov eax,
add ,eax ; = End of textmemory
mov edi, ;edi = Pointer to the new textmemory
mov edx, ;edx = Pointer to search-string
; = Bytes in the search-string
mov esi, ;esi = Pointer to replace-string
; = Bytes in the replace-string
mov eax,0

mov al,
cmp al,
je wfhastig
mov ,al
inc ebx
inc edi
add zahler,1
cmp ebx,
je wfendehastig
jmp wfhastloop
mov ecx,0
mov al,
cmp al,
jne wfhastweiter
inc ecx
cmp ecx,
jne wfhastig2

add ebx,ecx
mov ecx,0
mov al,
mov ,al
inc ecx
inc edi
add zahler,1
cmp ecx,
jne wbrastig

jmp wfhastloop

mov eax,zahler ; -> Return: Number of bytes in the new text memory

pop ebp
ret 28
Replace endp
Posted on 2002-04-19 08:39:52 by Nordwind64