Help Center

Local Navigation

Object: CharacterData

Availability

BlackBerry® Device Software version 4.6 or later

Extends

Node

Extended by

Comment, Text

The CharacterData object extends the Node object and can be used to access character data in the DOM. No DOM objects directly correspond to CharacterData; rather, the methods and properties are always inherited by other objects that require this functionality, such as Comment, Text, and CDATASection.

The content of this node is represented as UTF-16. CharacterData methods all work with numeric character offsets and text ranges, and manipulate ranges of text as a sequence of 16-bit units. Before invoking these methods, you should already know the ranges that you are manipulating.

CharacterData properties

Property name

Type

Description

Status

Availability

data

String

Specifies the character data of the current node.

writable

4.6 or later

length

int

Returns the length of the content of the data property or the CharacterData.substringData() method.

read only

4.6 or later

CharacterData methods

Method name

Description

Availability

appendData()

Appends the given string to the end of the data of the node.

4.6 or later

deleteData()

Removes the specified range of data.

4.6 or later

insertData()

Inserts a string at the specified location in the data.

4.6 or later

replaceData()

Replaces the specified range of data with the given string.

4.6 or later

substringData()

Returns the specified range of data from the node.

4.6 or later

Method: CharacterData.appendData()

Availability

BlackBerry® Device Software version 4.6 or later

The appendData() method appends the given string to the end of the data of the node.

Syntax

CharacterData.appendData( arg )

Parameters

Parameter

Type

Description

arg

String

The string to append.

Return values

None.

Exceptions

Exception

Description

NO_MODIFICATION_ALLOWED_ERR

This error is thrown if the Node is read only.

Method: CharacterData.deleteData()

Availability

BlackBerry® Device Software version 4.6 or later

The deleteData() method removes the specified range of data.

Syntax

CharacterData.deleteData( offset, count )

Parameters

Parameter

Type

Description

offset

int

The offset position from which to start removing.

count

int

The number of 16-bit units to delete. If the sum of offset and count exceeds the length of the data, then all 16-bit units from the offset to the end of the data are deleted.

Return values

None.

Exceptions

Exception

Description

INDEX_SIZE_ERR

This error is thrown if offset is negative, or is greater than the number of 16-bit units in the data.

NO_MODIFICATION_ALLOWED_ERR

This error is thrown if the Node is read only.

Method: CharacterData.insertData()

Availability

BlackBerry® Device Software version 4.6 or later

The insertData() method inserts a string at the specified location in the data.

Syntax

CharacterData.insertData( offset, arg )

Parameters

Parameter

Type

Description

offset

int

The offset position from which to start inserting.

arg

String

The string to insert.

Return values

None.

Exceptions

Exception

Description

INDEX_SIZE_ERR

This error is thrown if offset is negative, or is greater than the number of 16-bit units in the data.

NO_MODIFICATION_ALLOWED_ERR

This error is thrown if the Node is read only.

Method: CharacterData.replaceData()

Availability

BlackBerry® Device Software version 4.6 or later

The replaceData() method replaces the specified range of data with the given string.

Syntax

CharacterData.replaceData( offset, count, arg )

Parameters

Parameter

Type

Description

offset

int

The offset position from which to start replacing.

count

int

The number of 16-bit units to replace. If the sum of offset and count exceeds the length of the data, then all 16-bit units from the offset to the end of the data are replaced.

arg

String

The string with which to replace to the data.

Return values

None.

Exceptions

Exception

Description

INDEX_SIZE_ERR

This error is thrown if offset is negative, or is greater than the number of 16-bit units in the data.

NO_MODIFICATION_ALLOWED_ERR

This error is thrown if the Node is read only.

Method: CharacterData.substringData()

Availability

BlackBerry® Device Software version 4.6 or later

The substringData() method returns the specified range of data from the node.

Syntax

CharacterData.substringData( offset, count )

Parameters

Parameter

Type

Description

offset

int

The offset position from which to start extracting.

count

int

The number of 16-bit units to extract. If the sum of offset and count exceeds the length of the data, then all 16-bit units from the offset to the end of the data are extracted.

Return values

Returns the specified range of data.

Exceptions

Exception

Description

INDEX_SIZE_ERR

This error is thrown if offset is negative, or is greater than the number of 16-bit units in the data.

NO_MODIFICATION_ALLOWED_ERR

This error is thrown if the Node is read only.

Next topic: Object: Comment
Previous topic: Object: CDATASection

Was this information helpful? Send us your comments.