TE Edit Control Win32 / Win64 Help
Product page

TerSearchReplace

Search, replace or retrieve text.

BOOL TerSearchReplace(hWnd, search, replace, flags, StartPos, pEndPos, pBufSize)
Int TerSearchReplace2(hWnd, search, replace, flags, StartPos, EndPos)
HWND hWnd;The handle of the window to be accessed.
LPBYTE search;search text string
LPBYTE replace;replace text string
UINT flags;mode flags
long StartPos;start text position
long far *pEndPos;pointer to the end text position. This parameter is not used by the TerSearchReplace2 function.
Long EndPos;The end position of the string to replace. This parameter is not used by the TerSearchReplace function.
long far *pBufSize;pointer 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' long 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' long 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=TerSearchReplace2(hWnd,SearchString, "",
SRCH_SEARCH+SRCH_WORD + SRCH_CASE, pos, 0);

if (pos>=0) TerSearchReplace2(hWnd,"", ReplaceString,
SRCH_REPLACE, pos, pos+strlen(SearchString)-1);
}