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

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

Parameters
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.

Remarks
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.
Examples

Suppose you have an XML document structured like the following:

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

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"
  xmlns="http://www.w3.org/2001/vxml">

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

<form>
  <block>

    <script>
    <![CDATA[
    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));
    ]]>
    </script>
    
  </block>
</form>  

</vxml>


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