Character Indices in Text Strings

The IDLgrText property SELECTION_START uses the character index to position the cursor or the edge of a selection in the string defined by the text object. The character index is a zero-based identifier of the position just to the left of the character identified. For example, in the following string of characters:

String of characters 

the character index 7 specifies the position between the first space character and the letter "o" in the word "of."

In many cases, the location within a visible string of characters that corresponds to a particular character index value is obvious. However, when the text string specified to the IDLgrText object contains embedded formatting commands to change the size, position, or font face, the character indices no longer correspond directly to the locations of the characters displayed on the screen.

The following example shows regular text as well as superscript and subscript.

IdlgrTextcwq.gif

To create this example in an IDLgrText object, you would set the STRINGS property to the following value, which includes embedded formatting commands to create the superscript and subscript characters:

Text!USuper!DSub 
 

Note
You must also set the ENABLE_FORMATTING property of the IDLgrText object for embedded formatting codes to be honored.

The embedded formatting commands themselves are not displayed. In this example, any text following (!U) displays as supertext, while text following (!D) displays as subtext . See these characters in the grayed-out areas in the next example. This example shows the character index used when specifying a value via the SELECTION_START property.

The index specifies a location within the string. Placing the insertion cursor at an index number means that the cursor displays just before the character. In the following example, you would use index number 16 to place the insertion cursor after the last character.

Some indices do not make sense to use and are ignored. For example, index number 12 would place the cursor in between two format control characters.

T

e

x

t

!

U

S

u

p

e

r

!

D

S

u

b

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

Note
For more information on formatting text annotations, see Embedded Formatting Commands.

Examples

The following examples illustrate the IDLgrText properties SELECTION_START and SELECTION_LENGTH. The text selection between the bars equates to the following property values (if defined from left to right):

SELECTION_START=1

SELECTION_LENGTH=7

Because the direction of these properties can start from left to right or right to left, the same selection can also be defined from right to left as:

SELECTION_START=8

SELECTION_LENGTH=-7

Character_Indices_in_Text_Strings-26.jpg

A selection start between two characters like the one shown below is defined as:

SELECTION_START=10

SELECTION_LENGTH=0

Character_Indices_in_Text_Strings-27.jpg