Jump to content

Drive me nuts! String Equality why it isn't equal?


Recommended Posts

Hi all i got this code

While 1
    If  $data <> WinGetText($winname) Then
        $data = WinGetText($winname)
        Opt("WinDetectHiddenText", 1)
        $data1 = WinGetText($winname)
        Opt("WinDetectHiddenText", 0)
        
        $sString = StringTrimLeft($data1, 81)
        $lines = StringSplit($sString, @CRLF)
        
        if $lines[1]<>"" or $lines[1]<>$f then
        MsgBox($MB_TOPMOST, "KEY FOUND:", $lines[1], 2)
        MsgBox($MB_TOPMOST, $lines[1], $f, 2)
        clipput($lines[1])
        $f=$lines[1]
        
        else
    
        endif
        
            

    EndIf
    
    sleep(2000)

WEnd

This takes some hidden text from another c++ gui trims it then pops up a message box if the final trimmed string isn't blank OR isn't equal to its last/previous value (the $f)

The thing is that although with this code  

        MsgBox($MB_TOPMOST, $lines[1], $f, 2)
 

i find out both strings are equal and the 1st msgbox which says "key is:" SHOULD NOT be displayed & it gets displayed everytime although both strings are equal (like i find out with this code MsgBox($MB_TOPMOST, $lines[1], $f, 2) ) what am i doing wrong ?

look at my screenshot

cheers

1111.png

Edited by asiawatcher
Link to post
Share on other sites

Have you tried == rather than just =? Or try using StringStripWs to compare strings?  Also noticed you were using an "or" this will return true if either expression is correct?  StringStripWS example (untested):

;~ StringStripWS flag 7
;~  $STR_STRIPLEADING (1) = strip leading white space
;~  $STR_STRIPTRAILING (2) = strip trailing white space
;~  $STR_STRIPSPACES (4) = strip double (or more) spaces between words
Local $sData = StringStripWS($lines[1],7)
If $sData<>"" And $sData<>$f then
    MsgBox($MB_TOPMOST, "KEY FOUND:", $sData, 2)
    MsgBox($MB_TOPMOST, $sData, $f, 2)
    ClipPut($sData)
    $f=$sData
EndIf

 

Edited by Subz
Link to post
Share on other sites
  • JLogan3o13 changed the title to Drive me nuts! String Equality why it isn't equal?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...