How can i compare two strings and just check the first three characters only??? Example: I have a string in a buffer that consist of "123 456 789" I only want to check the first three characters of it. The rest is not needed. How can i make this work? When i try this, i get an error because the onetwothree string and the data in the buffer do not match. How can i limit the buffer to only three characters, or how can I only check for three characters?


.data
onetwothree    db    "123",0
;the buffer    ==    "123 456 789"

.code
invoke lstrcmp, addr buffer, addr onetwothree

Thanks guys, Nok.
Posted on 2001-02-27 21:58:00 by Nokturnal
Do it the "assembly" way :) Check out the string tutorial by and learn about STOSB & STOSW MOVSB & MOVSW SCASB & SCASW CMPSB & CMPSW get it at... www.safcon.cjb.net BTW , very good tut !
Posted on 2001-02-27 22:41:00 by anon

   .data
MyThreeString: db '123',0 ;We want to find this only\
OtherString:   db '345 456 567',0 'We have another string
   .code

...

   mov   eax, DWORD PTR OtherString
   and   eax, 0FFFFFF00 ;Just clear the lower byte
   cmp   eax, DWORD PTR MyThreeString
   jne   WeDontWantIt

...you do something her because you found what you were looking for...

WeDontWantIt:
Or, If you wanted to check every three bytes...

   .data
MyThreeString: db '123',0 ;We want to find this only\
OtherString:   db '345123614512',0,0,0 'We have another string
   .code

...
   mov   esi, OFFSET OtherString
   sub   esi, 3
TryToGetOurThreeBytes:
   add   esi, 3
   mov   eax, DWORD PTR 
   and   eax, 0FFFFFF00 ;Just clear the lower byte
   jz    ZeroMeansWeAreDone
   cmp   eax, DWORD PTR MyThreeString
   jne   TryToGetOurThreeBytes

...you do something her because you found what you were looking for, and esi points to those three bytes...


ZeroMeansWeAreDone:
Hope that helps :), bitRAKE This message was edited by bitRAKE, on 2/27/2001 11:10:50 PM (excuse me, I made the text fit narrower) This message was edited by Ernie, on 2/27/2001 11:27:58 PM
Posted on 2001-02-27 23:10:00 by bitRAKE