Recipe 9.29.
Replacing Text
Problem
You want to replace text.
Solution
Use the
replaceSelectedText( )
method to replace the highlighted text and replaceText( ) to replace a range
of text.
Discussion
The replaceSelectedText( ) method enables
you to replace the selected text in a text field. Simply pass the
method the string to use as the replacement text. For the method to
work, the text field must have focus:
_field.replaceSelectedText("new text");
Use the replaceText( ) method to replace
text within a text string given a starting and ending index. The
following replaces the text from index 100 to index 150, with the
new string specified by the third parameter:
_field.replaceText(100, 150, "new text");
|