Name

substringData: offset, count

Synopsis

This returns a DOMString that contains a subset of the string stored in the data attribute. The offset and count arguments define the substring. Although the offset argument must represent a valid position within the node data, the end-point of the substring could fall past the end of the data attribute. If this happens, the method returns everything between the offset position and the end of the data string.

Arguments

offset: unsigned long

Zero-based, starting offset of the substring to return. A valid offset must be >= 0 and < the length attribute of the node.

count: unsigned long

Count of characters to return.

Exceptions

INDEX_SIZE_ERR

Raised if the given offset is < 0, >= the length attribute, or if the count parameter is negative.

DOMSTRING_SIZE_ERR

Raised if the value that would be returned is too large to be contained by a DOMString type in the given implementation.

Java binding

public String substringData(unsigned long offset, unsigned long count)
                 throws DOMException;

Java example

// Get a reference to the CharacterData interface
CharacterData ndCD = doc.createTextNode("The truth is out there.");
     
// we only want the "truth"
String strTruth = ndCD.substringData(4, 5);
     
System.out.println("The substring is '" + strTruth + '\'');

Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.