v8902058@cc.nu.oz.au (10/13/90)
Hello... I'm sorry if this is a trival task, but I would like a function that compares two strings. I would like to be able to find if a string is equal to, less than, or greater than another string. I tried writing a routinue myself, but I just can't seem to do it, so I thought I'd ask. I wouldn't mind some code, or just the basic algorithm maybe. If anyone can help me, please email or post... Thanks. Bernard.
c8553709@cc.nu.oz.au (10/23/90)
In article <2203.27170055@cc.nu.oz.au>, v8902058@cc.nu.oz.au writes: > > Hello... > I'm sorry if this is a trival task, but I would like a function that > compares two strings. I would like to be able to find if a string is equal to, > less than, or greater than another string. I tried writing a routinue myself, > but I just can't seem to do it, so I thought I'd ask. > I wouldn't mind some code, or just the basic algorithm maybe. > If anyone can help me, please email or post... > Thanks. > Bernard. You will find that you can perform the logical operations =, < and > on strings that are made up of packed arrays, in standard Pascal, and so most likely on any version of Pascal. The following is some code... [program header] type string_type = packed array[1..80] of char; results = (same,ordered,unordered); [body of program] procedure compare_strings(string1,string2 : string_type; var result : results); begin if string1=string2 then result:=same else if string1>string2 then result:=ordered else result:=unordered end; [rest of program] In fact, as this is only one statement you do not need to make a procedure out of it, if not required often.