#1 Problem with WordPosL (and other string types?)

Strings (5)

Exported from Bugzilla, issue 1666.

--- Comment added on 11/28/2001 3:33:02 PM ---
Customer Reports:

> Dear TurboPower Team,
> I'm having a problem with WORDPOS and I need your help.
> Please consider the following code snippet.
> procedure TfrmWorkPlace_General_K1.wwdbe_CodeExit(Sender:
> TObject);
> var
> S,T : string;
> C : cardinal;
> begin
> S := 'S10 S11 S13 S21 S29 S20';
> T := '1';
> if WordPosL(S,' ',T,1,C) = true then
> ShowMessage('T has been found in postion ' +
> IntToStr(C))
> else
> ShowMessage('T has not been found in this sentence.');
> end;
> When T is given the value of 1, I would NOT expect it to be
> found as a word in sentence S. However, in the example
> above, it hits the true path and returns a postion of 7.
> If T is changed to 'S2', again I would NOT expect it to be
> found as a word in sentence S. However, it hits the true
> path again and returns a position of 21.
> Am I doing something wrong or is there a bug in the code for
> this function? Please advise.

Your code looks correct and I've reproduced your results here. It appears
indeed to be a bug in WordPos.

It seems only to surface if the sought string is repeated immediately preceding
a delimiter character (as in the "S11 " segment of your example string).

Similar results arise from a situation like:

S := 'ababab babcabc ';
T := 'abc';

which finds the "abc" substring starting at position 12.