Re: String compare

new topic     » goto parent     » topic index » view thread      » older message » newer message

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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu