Articles 3D Audio Custom Controls General RB Graphics Hacks Mac OS X Menus Novelty Printing REALbasic 2005 REALbasic 2006 Registration Resources Reviews Serial Speech Sockets XML Video Resource Links News Current News February 2006 January 2006 December 2005 November 2005 October 2005 September 2005 August 2005 July 2005 June 2005 May 2005 April 2005 March 2005 ![]() REALbasic for Dummies by Erick Tejkowski ![]() Learning REALbasic through Applications REALbasic for Macintosh REALbasic Cross-Platform Application Development
Older files are in Stuffit 5 or greater format. Newer files are ".Zip". Download StuffIt Expander |
|
Word Finding
Design
That's all there is to it. Create a module named "WordMatching" or whatever you want, and create a method inside of it: MatchWord(source as string, find as string, start as integer, sensitive as boolean) As integer After that, just create a window with two fields and a button labeled "Find". (The example project has this all done for you.) The EFBody EditField will be our "source" field and the EFSearch EditField will containt the word we're looking for. Obviously, the Find button initiates the search.
The MatchWord Function After that we're going to enter a loop which keeps executing while possible matches are found. If no match is made or no possible matches are found, the loop will exit. The first line of the loop checks for any possible matches. The next three lines then check to see if the case of the find string and the match are the same. StrComp is a built-in function in REALbasic which does case-sensitive string comparision. If StrComp returns 0, then the strings are equivalent. If the case does not match and case-sensitivity is on, the offset value is set to 0 signalling that it is not a match, and that the loop should iterate once more to see if a new match can be found. After that, we check the characters immediately to the left and right of the match to see whether or not they are allowable word separators. If they are, then we've got a match and the loop exits since offset does not equal zero. Note that we check for offset to be > 1 when checking left and offset > 0 and offset <= theEnd when checking right. This not only checks to see if the word is at the edges of the field (because if it is, it is automatically a match for that respective side), but it also makes sure there's a possible match since offset must not be 0 for either testing to occur. Function MatchWord(source as string, find as string, start as integer, sensitive as boolean) As integer
The Find Button Sub Action() The Finished Product
|
||||
|
||||||||||||||||||||||||||||||||
Maintained by the Staff of ResExcellence. This entire site ©1997-2006 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement.
[an error occurred while processing this directive]