replaceData: offset, count, arg
This replaces a substring within the data
attribute with another string value
arg
, using the specified
offset
and count
parameters.
The offset of the beginning of the replacement region.
The number of characters to replace. If offset
+ count
is >= the length
attribute, everything
beyond the offset
character position is replaced.
The replacement string.
The replaceData
operation
is the equivalent of the following code fragment:
cdNode.deleteData(offset, count); cdNode.insertData(offset, arg);
Raised if the offset
parameter is not a valid,
zero-based index into the data
DOMString
.
Raised if the node is read-only.
// Create a new Text object and reference the CharacterData interface CharacterData ndCD = doc.createTextNode("The truth is not out there."); // replace the truth String strFind = "truth"; String strReplace = "dog"; ndCD.replaceData(ndCD.getData( ).indexOf(strFind), strFind.length( ), strReplace); System.out.println(ndCD.getData( ));