Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!samsung!munnari.oz.au!metro!nuts!cc.nu.oz.au!c8553709 From: c8553709@cc.nu.oz.au Newsgroups: comp.lang.pascal Subject: Re: Comparing strings... Message-ID: <2665.27249cc2@cc.nu.oz.au> Date: 23 Oct 90 09:40:50 GMT References: <2203.27170055@cc.nu.oz.au> Organization: University of Newcastle Lines: 37 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.