Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!purdue!mentor.cc.purdue.edu!mace.cc.purdue.edu!aqm From: aqm@mace.cc.purdue.edu (Steve Weinrich) Newsgroups: comp.lang.pascal Subject: Re: Hashing.... Message-ID: <3225@mace.cc.purdue.edu> Date: 26 Sep 89 15:03:55 GMT References: <4337@internal.Apple.COM> Distribution: na Organization: Purdue University Computing Center Lines: 66 athos@apple.com (Rick Eames) writes: >hashing it is a good way. Having figured out what hashing is...does any >one have a good hash function for finding a string inside of another >string? Well Rick, there are several ways to go about finding a string within a string. If all you will be doing with each string is trying to find it within another string, then I'm not sure a full fledged hashing function would be worth your while. Nothing like using an elephant gun to kill an ant. What you might consider doing instead is a simple (yes, I said it! simple! ugggg!) sequential search. But do it in a reasonable fashion. Something similar to the code below might be what you are looking for: root = string you are search THROUGH find = string you are looking FOR function In_String(root : TyString, find : TyString): boolean; Rindex, Findex, temp_index : integer; found, test : boolean; begin found := false; test := true; Rindex := 1; Findex := 1; temp_index := 1; while (Rindex <= (StringLength + 1)) and (not found) do begin if root[Rindex] = find[1] then begin Findex := 1; temp_index := Rindex; test := true; found := false; while test and not(found) do begin test = (root[temp_index] = find[Findex]) do temp_index := temp_index + 1; Findex := Findex + 1; if Findex > StringLength then found := true; end; end else begin Rindex := Rindex + 1; end; {while} InString := found; end; {function} Good luck. This was written on the fly, probably forgot some error checking, but you get the idea. -- Steve Weinrich - Purdue University - Unix Group Support E-Mail: aqm@cc.purdue.edu