/*********************************************************** strmatch.c -- 文字列照合 ***********************************************************/ Function position(text As *Byte, pattern As *Byte) As Long Dim i As Long, j As Long, k As Long, c As Long
c = pattern[0]: i = 0 while (text[i] <> 0) if (text[i] = c) Then
k = i+1: j = 1 while (text[k] = pattern[j]) And (pattern[j] <> 0) k++: j++ Wend
if (pattern[j] = 0) Then position= k - j /* 見つかった */ Exit Function End If End If i++ Wend position = -1 /* 見つからなかった */ End Function
#N88BASIC Dim i As Long Dim text = "私の名前は平井公彦" As *Byte Dim pattern[3] = ["私の", "名前は", "平井公彦", "阿部高和"] As *Byte
Dim out[100] As Byte For i=0 To 3 wsprintf(out, Ex"position(\q%s\q, \q%s\q) = %d\n", text, pattern[i], position(text, pattern[i])) Print MakeStr(out) Next