substringData Method
Last Updated: 08-25-2005
Extracts a range of characters from the contents of a TextNode, Comment, or CDATASection.

var sSubstring = object.substringData(iOffset, iCount);

iOffset Required. The start offset of the substring to extract. Offsets start at 0.
iCount Required. The number of characters to extract.

Return Value
The substring of the contents starting at the specified offset, for the specified number of characters.

If the sum of iOffset and iCount exceeds the length of the initial string, then all characters from the offset through the end of the string are returned.

Suppose you have an XML document structured like the following:

<?xml version="1.0"?>
<?access-control allow="*"?>

Here is a program that extracts substrings. Given the XML document shown above, it extracts from the text string "basket" the substring of 4 characters starting at offset 0, resulting in the string "bask". The program then extracts a substring at the end of the string, and a substring in the middle.

<vxml version="2.1"

<data name="dom" src="dom_substringData.xml"/>


    var root = dom.documentElement;
    var textNode = root.firstChild;
    var textLength = textNode.length;
    vxmllog("The text is " + textNode.nodeValue);
    vxmllog("The substring starting at offset 0 for 4 characters is " + 
      textNode.substringData(0, 4));
    vxmllog("The substring at the end starting at offset 2 is " + 
      textNode.substringData(2, (textLength-2) ));
    vxmllog("The substring starting at offset 1 for 3 characters is " + 
      textNode.substringData(1, 3));


Applies To
CDATASection, Comment, TextNode
[24]7 Inc.| Terms of Service| Privacy Policy| General Disclaimers