ReplaceText

Description

Replaces selected text in an edit control with a specified string.

Applies to

DataWindow, EditMask, MultiLineEdit, SingleLineEdit, RichTextEdit, DropDownListBox, and DropDownPictureListBox controls

Syntax

editname.ReplaceText (string )

Argument

Description

editname

The name of the control in which you want to replace the selected string.

In a DataWindow control, the text is replaced in the edit control over the current row and column.

string

The string that replaces the selected text.

Returns

Long. Returns the number of characters in string and -1 if an error occurs. If any argument’s value is null, ReplaceText returns null.

Usage

If there is no selection, ReplaceText inserts the replacement text at the cursor position.

In a RichTextEdit control, the selection can include pictures.

NoteOther ways to replace text To use the contents of the clipboard as the replacement text, call the Paste function, instead of ReplaceText.

To replace text in a string, rather than a control, use the Replace function.

Examples

Example 1

If the MultiLineEdit mle_Comment contains Offer Good for 3 Months and the selected text is 3 Months, this statement replaces 3 Months with 60 Days and returns 7. The resulting value of mle_Comment is Offer Good for 60 Days:

mle_Comment.ReplaceText("60 Days")

Example 2

If there is no selected text, this statement inserts "Draft" at the cursor position in the SingleLineEdit sle_Comment3:

sle_Comment3.ReplaceText("Draft")

See also