[Cook] Comparing two strings for equality

Peter Miller millerp at canb.auug.org.au
Sun Jun 22 23:14:36 EST 2003


On Thu, 2003-06-19 at 07:01, Jody Hagins wrote:
> I am a bit confused by how I should compare two strings for equality. 
> It seems that I should be using something like...
> 
> 
> if [in [string1] [string2]] then
> {
>   /* The two strings are equivalent */
> }
> 
> 
> but I am a bit bothered by the implicit meaning of "in" especially of
> [string2] happens to expand to a word list.

Cook variables are lists of strings, they are not strings.

If you want to compare two variables for equality, you have to turn them
into simple strings first.  Try
 
    if [in [unsplit "-" [string1]] [unsplit "-" [string2]]] then
    {
        /* The two strings are equivalent */
    }

but note the ambiguity of comparing a list of two element "a" "b" with a
list of one element "a-b".  You unsplit separator needs to be unlikely
to appear in either string.

Of you could explicitly only compare the first word, using

    if [in [firstword [string1]] [firstword [string2]]] then
    {
        /* The two strings are equivalent */
    }

-- 
Regards
Peter Miller <millerp at canb.auug.org.au>
/\/\*        http://www.canb.auug.org.au/~millerp/

PGP public key ID: 1024D/D0EDB64D
fingerprint = AD0A C5DF C426 4F03 5D53  2BDB 18D8 A4E2 D0ED B64D
See http://www.keyserver.net or any PGP keyserver for public key.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: This is a digitally signed message part
URL: <http://lists.auug.org.au/pipermail/cook-users/attachments/20030622/6ba1e1f3/attachment.pgp>


More information about the Cook-users mailing list