TerSearchReplace
Search, replace or retrieve text.
bool TerSearchReplace( ref search, replace, flags, StartPos, ref pEndPos, out pBufSize)
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, the TerSearchReplace function returns its absolute character position via the 'pEndPos' int pointer.
If the search string is located, the TerSearchReplace2 function returns its absolute character position 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. The size of the retrieved text is returned via the 'BufSize' int pointer. The actual text is returned via the 'search' argument. This function returns even the hidden text.
Comments: This Retrieve mode is not available when this function is used as an ActiveX control method. The function must be used as a DLL function to use the retrieve mode.
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=tern.TerSearchReplace2(SearchString, "",
tc.SRCH_SEARCH+tc.SRCH_WORD+ tc.SRCH_CASE, pos, 0);
if (pos>=0) tern.TerSearchReplace2("", ReplaceString,
tc.SRCH_REPLACE, pos, pos+SearchString.Length-1);
}