1. Re: comparing sequences
- Posted by David Cuny <dcuny at LANSET.COM> Oct 22, 2000
- 418 views
Paul Kerslake wrote: > Is there a way to compare 2 objects like so: Rather than using objects, you probably should declare your lists as sequences. The basic methods for comparing sequences as if they were strings are: equal( o1, o2 ) For example: if equal( "money, it's a gas", "money, it's all cash" ) then ... If you want to do a greater than/less than sort of comparisons, use: compare( o1, o2 ) For example: procedure compare_strings( sequence s1, sequence s2 ) integer result result = compare( s1, s2 ) if result = 0 then puts( 1, "%s and %s are the same\n", {s1, s2} ) elsif result = -1 then puts( 1, "%s is less than %s\n", {s1, s2} ) else puts( 1, "%s is greater than %s\n", {s1, s2} ) end if end procedure compare_strings( "led zepplin", "pink floyd" ) To check for the length of a sequence, you can use: length( s ) For example: ledzepsong={"theres a lady in short", "all that glitters is gold", "and she's buying a ", "stairway to heaven....."} printf( "There are %d lines in the song\n", {length( ledzepsong} ) which is sometimes abbreviated to: if not length( s ) then ... I hope this helps! -- David Cuny