ID:172869
 
Could someone educate me on how to go about finding a sequence of characters, if possible? IE, it returns true if it finds a,b,c in that specific order, but false in any other instance such as c,b,a or b,a,c, etc.
    proc
//////////////// FindOrderedText(txt,...) //////////////////////
// From homelib by Dan@dantom.com
// Thanks Dan!!
//
//This is a quick-and-dirty sentence matcher to be used
//by residents for scanning conversational text. It is intended
//to be fast rather than smart. Still, it works pretty well.
//
//Returns true if the specified word sequence is found.
//
//Example usage: FindOrderedText(txt,"who","created|made","you")
////////////////////////////////////////////////////////////////

FindOrderedText(txt)
var
w
pos
lastpos = 1

for(w in args)
if(w == txt) continue
pos = findtext(txt,w,lastpos)

if(!pos) find_alt_word:
if(!findtext(w,"|")) return
//alternate words separated by |
var/global/alt_lst[0] //for speed, cache alt lists here (indexed by original string)
var/alts = alt_lst[w]
if(!alts)
alts = AltWordList(w)
alt_lst[w] = alts
for(w in alts)
pos = findtext(txt,w,lastpos)
if(pos) break find_alt_word
return

lastpos = pos
return lastpos

AltWordList(w)
var/lst[0]
var/endpos = lentext(w)+1
var/pos
var/lastpos = 1
while(lastpos < endpos)
pos = findtext(w,"|",lastpos)
if(!pos) pos = endpos
lst += copytext(w,lastpos,pos)
lastpos = pos+1
return lst

In response to Shadowdarke (#1)
Curiously your routine doesn't advance pos by the number of characters in the found word. And if the word has alternates separated by | yet the entire set of alternates matches txt exactly, the result will be incorrect. Tsk tsk!

Lummox JR
In response to Lummox JR (#2)
Blame Dan. It's from his homelib. ;)