TerSearchReplace
Search, replace or retrieve text.
boolean TerSearchReplace(search, replace, flags, StartPos, pEndPos)
Int TerSearchReplace2( search, replace, flags, StartPos, EndPos)
String search; | search text string |
String replace; | replace text string |
int flags; | mode flags |
int StartPos; | start text position |
int pEndPos; | variable to the end text position. This parameter is not used by the TerSearchReplace2 function. |
int EndPos; | The end position of the String to replace. This parameter is not used by the TerSearchReplace function. |
int BufSize; | variable to the size of the retrieved text. This parameter is not used by the TerSearchReplace2 function. |
Description: This function has three operational modes: search, replace and retrieve.
Search Mode: To initiate this mode, set the SRCH_SEARCH flag in the 'flags' parameter. You can also set the following bits in the 'flags' parameter:
SRCH_CASE Case sensitive search SRCH_WORD Match whole words SRCH_SCROLL Scroll the located text into view. SRCH_SKIP_HIDDEN_TEXT Skip over the hidden text SRCH_BACK Search in the backward direction SRCH_NO_REPLACE_PROT_TEXT Do not replace protected text.
The search String is passed via the 'search' parameter. The search String consists of regular text and certain special characters. The special characters are inserted using the '^' prefix:
^p Paragraph character ^t Tab character ^m Manual page break ^b Section break ^+ Em dash ^- En dash ^^ ^ character.
The initial search location is specified by the 'StartPos' parameter. This parameter specifies the absolute character position since the beginning of the file.
If the search String is located using the TerSearchReplace function, the absolute character position of the located text can be retrieved as following:
EndPos=tej.TerGetOutInt("EndPos")If the search String is located using TerSearchReplace2 function, then the absolute character position is returned via function return value. If the String is not found, then this function returns -1.
Replace Mode: To initiate this mode, set the SRCH_REPLACE flag in the 'flags' parameter. This function replaces the text between the 'StartPos' and 'pEndPos' (or EndPos for the TerSearchReplace2 function) absolute character positions by the specified replacement text. The replacement text is specified by the 'replace' argument.
Retrieve Mode: To initiate this mode, set the SRCH_RETRIEVE flag in the 'flags' parameter. This function retrieves the text between the 'StartPos' and 'EndPos' absolute character positions. This function returns even the hidden text. The text between the StartPos and EndPos can be subsequently retrieved upon the successful return from this method as following
String RetrievedText=tej.TerGetOutStr("Search")Return Value for the TerSearchReplace function:
This function returns true if successful. Otherwise, it returns a false value.
Return Value for the TerSearchReplace2 function:
When the SRCH_SEARCH flag is specified, the return value indicates the absolute character position of the String found. It returns -1 if the String is not found.
When the SRCH_REPLACE flag is specified, this function returns true if successful. Otherwise, it returns a false value
Example:
pos=0;
while (pos>=0) {
pos=tej.TerSearchReplace2(SearchString, "",
tej.SRCH_SEARCH+tej.SRCH_WORD+ tej.SRCH_CASE, pos, 0);
if (pos>=0) tej.TerSearchReplace2("", ReplaceString,
tej.SRCH_REPLACE, pos, pos+SearchString.Length-1);
}