Find and replace basics

Search direction and start position

The actual finding of a given text phrase is achieved with usage of methods indexOf and lastIndexOf of class String. Both methods return the position a given text phrase is found at inside another string. indexOf and lastIndexOf accept an optional position to start the search from so that the variations of these methods already can be taken to implement searching from start or from end of a document in either upward or downward direction.

Whole word search

Methods indexOf and lastIndexOf find any occurrence of a given search phrase as either part of a word or whole word. To restrict matches to whole words a character array of word separators WORD_SEPARATORS is used. Method isSeparator is used in method doFind of class FindReplaceDialog to determine whether or not a found occurrence is a full word.

Case sensitive search

Methods indexOf and lastIndexOf are case sensitive. They return a found occurrence only when capitalization of letters matches the given search phrase. To do a case insensitive search method toLowerCase of class String is applied to both the search phrase and the text to search in before a find operation is initiated.

Read on in the next topics to find out more about how these basics are applied in the user interface and logic of SimplyHTML.