condoman Posted March 8, 2005 Posted March 8, 2005 While working on a new program I was surprised that $B will equal 1 when a null is used. I worked around this but am curious why $B is not 0. $A = "ABCD" $B = StringInStr($A,"") Thanks
Blue_Drache Posted March 8, 2005 Posted March 8, 2005 I hate NULLs... This discussion resurfaces every so often. When AutoIt supports binary data types, this discussion will finally have merit.for now.... never do this...StringInStr($A,"")Lar.<{POST_SNAPBACK}>Does that apply to testing to see if it returns a null?Example:If Not StringInStr($b,"ABCD") = "" then ; do something if "ABCD" exists inside $b Else ; do something if "ABCD" does NOT exist inside $b EndIfI use this structure extensively and now that you've said something to this effect, I'm worried that a future version my break all my constructs. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
Valik Posted March 8, 2005 Posted March 8, 2005 Does that apply to testing to see if it returns a null?Example:If Not StringInStr($b,"ABCD") = "" then ; do something if "ABCD" exists inside $b Else ; do something if "ABCD" does NOT exist inside $b EndIfI use this structure extensively and now that you've said something to this effect, I'm worried that a future version my break all my constructs.<{POST_SNAPBACK}>That example looks botched... Let's break it down:If StringInStr() = ""If the sub-string is found, this returns 1 and becomes:If 1 = ""That is false, strings (Whether empty or not) resolve to 0. So that means if the sub-string is not found, you get:If 0 = ""Which is true.However, you've used the NOT operator as well. It inverts the argument immediately following it. So you've effectively reversed the return value of StringInStr(). Thus, when finding the sub-string, you are left with this:If 0 = ""And when not finding it:If 1 = ""Or, in other words. You're using a long winded and confusing approach.To test if the sub-string is present:If StringInStr()And to test if it's not present:If Not StringInStr()I don't know where you were going with the Not StringInStr() = "" thing but it is bad code because it achieves the exact same effect as above.I think what you meant is this:If $b <> "" And StringInStr($b, "abcd") Then ; Found the sub-string Else ; Did NOT find the sub-string EndIf
condoman Posted March 8, 2005 Author Posted March 8, 2005 I avoid negative conditions whenever possible. This surfaced because I was looking for a quick and dirty way to tell if a given file extension was one of the multiple extensions I wanted to process. When there was no extension the condition was true and I did not expect that. I ended up testing for a null extension before checking my list of extensions. Thanks
golfjrr Posted March 8, 2005 Posted March 8, 2005 While working on a new program I was surprised that $B will equal 1 when a null is used. I worked around this but am curious why $B is not 0.$A = "ABCD" $B = StringInStr($A,"")Thanks <{POST_SNAPBACK}>Yea I tripped on this at the version change some of my stuff quit working. I just wrote a rather mornic function and call it instead of stringisspace as in my little world, empty is the same as whitespace. Func StringIsEmpty ( $sstring ) local $sstring if stringisspace ($sstring) or $sstring = "" then return 1 else return 0 endif endfunc
Blue_Drache Posted March 8, 2005 Posted March 8, 2005 (edited) @Valik I see.... I overcomplicated it.... Re-reading the help file I see that it returns a zero if it wasn't found, so maybe I should test for that instead. *Wanders off to re-code about 5,000 lines........* Edited March 8, 2005 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now