Re: String compare
- Posted by David Cuny <dcuny at LANSET.COM> Sep 10, 1998
- 530 views
Roy wrote: >I'm trying to compare two strings. You can only use '=' on basic types. For reasons that continue to irritate me, Robert has chose to follow the C model and require a function call for more complex comparisons: if compare( st, "abc" ) = 0 then will work. Essentially, you can think of compare() as subtracting the two value. It returns -1, 0 or 1 depending on if the values are less than, equal, or greater than each other. A common error (not just newbie; I make it all the time) is to write: if compare( st, "abc" ) then which is the opposite of what you want. It might be helpful to write your own function, along the lines of: function eq( object o1, object o2 ) return compare( o1, o2 ) = 0 end function so you can write: if eq( st, '123" ) then instead. Hope this helps! -- David Cuny