Subject: Position of first match in text
From: "Stadin, Benjamin" <[EMAIL PROTECTED]>
Date: Sat, 19 Mar 2005 06:40:09 -0000
I'm using StrStr to compute the position of the first match in a text
string (TxtGlueFindString and FindStrInStr don't give the correct Position
if the string doesn't start with the searched string, although they find a
match...).
My problem is that I get only the last text match, but I want the first.
The Palm docs say StrStr "Returns a pointer to the first occurrence of
token in str or NULL if not found". Do I miss something or are the docs wrong?
Does anybody know a another way to get the first match?
That's what I currently do:
Char* strPos;
strPos = StrStr (out, CurrentFilter);
outPos = (UInt32)(strPos) - (UInt32)(out);
You should always handle a NULL return from functions such as StrStr()
Char * strPos = StrStr (out, CurrentFilter);
if (strPos == NULL) outPos = -1L; // some default value
else outPos = strPos - out; // pointer arithmetic doesn't need a cast
It would have been very nice if Palm had built an optimized API function
StrStrCaseless(...)
Roger Stringer
Marietta Systems, Inc. (www.rf-tp.com)
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/