hello all,

i am trying to code a little string manipulator program to increase my strength in asm

first thing is if i have a static variable, say for instance

declarations:

szStr1 db ".eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", 0 ; this has 32 'e' chracters and one '.'
szStr2 db 24h (?)

then i use SendMessageA and WM_GETTEXT to get what i inputted in my program into a var name szStr2
say i input in the word archmage

now, note that sendmessagea returns the # of characters in the string you put in in eax
so, i want to do this ->
i want to add archmage to the beginning of szStr1 and subtract the number of letters added from the end of it
so in result i get

"archmage.eeeeeeeeeeeeeeeeeeeeeeee" ; (notice it cuts 'e' characters from the end of the string and adds the 8
; characters of archmage to the front)

so far i have

call SendMessageA, hWndName, WM_GETTEXT, MAXCHARS+1, offset sztempvr2

lea esi, ;load the address of static string

lea edi, ;load the address of the inputted string

add edi, eax ; eax holds number of characters you inputted so add that to edi's address

sub esi, eax ; subtract the number of inputted characters from the original string

;--begin adding of strings--

mov ecx, 21h

cld

rep movsb

;--stop adding of strings--


but this doesn't work, if you remove the "sub esi, eax" it just adds the string together (the inputted one in first + the static string) -- is there a way to then cut the amount of characters from the end result?

(i appreciate the help, dont worry if you code in MASM, i will be able to convert from MASM to TASM)
Posted on 2002-10-22 16:59:33 by archmage
GetWindowTextLength,hXXX
add eax,1
GetWindowText,hXXX,addr Buffer,eax

this codes Works well under my system.
Posted on 2002-10-23 03:55:55 by Const.Ex
archmage,

This does not sound right, i am very rusty in TASM but it still uses much the same method as MASM to get the length of string data in the .DATA section. You should have a keyword like LENGTH, SIZE or similar to get the length at assemble time.

To do it dynamically you would have to write a string length procedure that counted the length excluding the terminator.

You normally use the API SendMessage() with the message WM_GETTEXT to load text from some API defined source into a buffer that you allocate, either in dynamic memory or in the DATA section.

Good luck with it.

hutch@movsd.com
Posted on 2002-10-23 06:26:51 by hutch--
hmmm.. you cannot just substract eax from esi, if that is so you are stepping into other datas of the program and not the string array.

what about



.data?
temp db 128 dup (?)

.code
lea edi, temp
lea esi, szStr1
mov ecx, 36
rep movsb; temp store copy of the szStr1

lea edi,szStr1
lea esi,temp
add edi,eax
mov ecx, 36
rep movsb

lea edi,szStr1
lea esi,szStr2
mov ecx,eax
rep movsb


*Note:Hope this works, I never tried it out yet
Posted on 2002-10-23 08:01:56 by roticv
roticv, very close...it's fun to try programming without assembler and see how you do.

.data?

temp db 128 dup (?)

.code
lea edi, temp
lea esi, szStr1
mov ecx, 36
rep movsb; temp store copy of the szStr1

lea edi,szStr1
lea esi,temp
add edi,eax
mov ecx, 36
sub ecx, eax ; without this we'd overrun szStr1
rep movsb

lea edi,szStr1
lea esi,szStr2
mov ecx,eax
rep movsb
Same disclaimer as roticv - haven't tested it.
Posted on 2002-10-23 10:21:56 by bitRAKE
....


txt DB "stryker", 0

....

bfr DB 32 DUP(?)

....

mov edx, OFFSET txt
xor ecx, ecx
mov ebx, OFFSET bfr

__copy:
mov al, BYTE PTR [edx+ecx]
mov BYTE PTR [ebx+ecx], al
inc ecx
test al, al
jnz __copy

mov BYTE PTR [ebx+ecx-1], "."

__extra:
mov BYTE PTR [ebx+ecx], "e"
inc ecx
cmp ecx, SIZEOF bfr
jb __extra

mov BYTE PTR [ebx+SIZEOF bfr], 0
I do not assume the buffer will always have the same result especially if it is being written over and over. That's why, the code above needs to write the letter e each time, to make sure it's consistent what the original poster is trying to do. :)
Posted on 2002-10-23 19:43:40 by stryker
interesting .. mine is almost the same as bitRake's jsut that mine store the results in the temp buffer to form the buffer than is shift to the right by the value in eax. I also thought of another method, but that will destroy the value of szStr1.
Posted on 2002-10-24 09:55:35 by roticv