Hi! I'm afraid my question is very stupid, but I can't find a solution: How can I find out if two strings are the same? Concrete example: I let the user choose a file by an open dialog. Now I want to find out if the extension of the chosen file is, let's say, ".exe". Thanx a lot in advance :) stem
Posted on 2001-03-20 08:40:00 by stem
First you need a template to test against:
tstExtension: db ".exe",0
Since it's only four bytes, some programmers would just test a DWORD, but this allows for easy changes. Second, you need to find the length of the string that you are testing against, because we need to start at the end. This will prevent us from finding 'Exe.exe.bat' as a program :) Next look at each character for a '.', or the first character of our template above. Then move forward testing the rest of the characters for equality. You have to make sure that you don't overrun either of the strings during the comparison. I would just use the API routines that already exist though :) lstrlen lstrcmp

    invoke lstrlen, addr tstExtension
    push   eax
    invoke lstrlen, addr TestString
    pop    ecx
    sub    eax, ecx
    jle    @F ;Couldn't be a match (string smaller or equal extension length)
    mov    ecx, addr TestString
    add    ecx, eax
    invoke lstrcmp, addr tstExtension, ecx
    test   eax,eax
    jne    @F
...the extension is .exe here (do something)

@@: ;Wrong extension
This routine doesn't allow the test string to be just an extension. Hope that helps, bitRAKE
Posted on 2001-03-20 10:31:00 by bitRAKE
if you ONLY WANT to check a 4 byte extension you can do this like this:

invoke lstrlen,addr ChoosenFile ;get string length
add eax,offset ChoosenFile ;add offset to result
sub eax,5 ;sustract 4 byte & the last 0
cmp dword ptr ,"e.xe" ;compare extension with ".exe"
jnz @noexe ;".exe" not found
mh, please note that there could be some errors... (i've got no api-ref and no compiler here) 1. i don't know yet if lstrlen returns the size without the last terminating zero = sub eax,5 could be wrong 2. i hate this intel convention, maybe "e.xe" is wrong This message was edited by drcmda, on 3/20/2001 12:03:29 PM
Posted on 2001-03-20 11:01:00 by drcmda
I just reciently wrote some code for that very same purpose. I modified the 'db' string to:

szExtenions db "Exe Files",0,"*"
    szIT    db ".exe",0,0
Basically szExtensions will still operate as normally, but i added an extra lable at the '.exe' for alternate references: then in the code i used a M32LIB command, InStr ( pretty sure this is it ~ in at school right now, so cant check ) like so:

  invoke InStr, addr szFileName, addr szIT
     ;The .exe is in the file name
     ;The .exe is not in the file name


Anywho, i hope this helps, Im pretty sure i got the label name wrong at the top (szExtensions), but im sure you get the point. NaN
Posted on 2001-03-20 13:33:00 by NaN
Personally, I hate three letter extension. I've been using computers all through the three letter extension thing. I hate 'em, I hate 'em, I hate 'em. Why do we have to continue this horrible convention? I'm going to code away from it every chance I get :) I like: InString.PROC.assembly.html Look how it tells you what it is? Then again I have 92gigs of hard drive space and 100,000+ files. So I need a better way to name stuff (like InString.PROC.assembly.html.zip) Okay, I'm going to an extreme here, but you get my rant right :P My doctor says to take deep breathes :) bitRAKE
Posted on 2001-03-20 13:50:00 by bitRAKE
There is a much simpler way of doing this comparison using a couple of the procedures from the MASM32 library. Use the szRight proc to get the last 4 bytes of the path/filename, convert it to lowercase and then do the compare against a preset test string,

ExeTst db "exe",0
Should work fine and save a lot of messing around. Regards, hutch@pbq.com.au
Posted on 2001-03-20 15:24:00 by hutch--
Hutch's method is probably better than the InString version, as it is a more direct comparison. But I dont see the need to redeclair another 3 bytes of data when you have done it once already.. Add a second label to the right location of the string and your fine for both the open/save dialogs as well as for any other string comparisions on the extension.

        .if wParam == 1001
            jmp @F
              szTitleO   db "Open A File",0
              szFilterO  db "Exe Files",0,"*"
              szEXE      db ".exe",0,0
          ; --------------------------------------
          ; szFileName is defined in Filedlgs.asm
          ; --------------------------------------
Just pointing this out :P NaN
Posted on 2001-03-20 21:35:00 by NaN
I didn't use InString :) either :) bitRAKE
Posted on 2001-03-20 21:37:00 by bitRAKE