delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/01/29/08:51:39

From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: strings i think...?
Date: 29 Jan 2001 13:38:53 GMT
Organization: Aachen University of Technology (RWTH)
Lines: 28
Message-ID: <953rpd$nft$1@nets3.rz.RWTH-Aachen.DE>
References: <O%Mc6.2344$YT3 DOT 73514 AT news6-win DOT server DOT ntlworld DOT com>
NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de
X-Trace: nets3.rz.RWTH-Aachen.DE 980775533 24061 137.226.32.75 (29 Jan 2001 13:38:53 GMT)
X-Complaints-To: abuse AT rwth-aachen DOT de
NNTP-Posting-Date: 29 Jan 2001 13:38:53 GMT
Originator: broeker@
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

[Note: this problem is almost entirely unrelated to DJGPP --- nor even
to any particular programming language, either. You had better asked
about it elsewhere.]

D Borland <d DOT borland AT ntlworld DOT com> wrote:
[...]
> user types: 'bike green suzuki'
> programs string: 'green bike suzuki'

... and you want these two strings to compare as 'equal', right? In
that case, you'll want to preprocess both strings before comparing
them. One way would be to split each into a list of words, and sort
that list alphabetically. Then you can either concatenate those words
again, to form a new single string, or keep storing them as a sorted
list of individual strings (can be pointers into the original string,
if you kept that).

Then, you can do the comparison by using strcmp() on the sorted lists,
element by element. Due to the sorting, both of the above inputs would
end up as

	"bike", "green", "suzuki"

and thus compare equal.

-- 
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019