beetlebug▾
/

text count

Counts the characters, the lines, or other units between two indices.

PATHNAME count ?OPTION ...? INDEX1 INDEX2

Description

Counts from INDEX1 to INDEX2. A count is negative when INDEX2 is before INDEX1. The options name the units, and the default is -indices:

With more than one unit, gives a list of the counts in the order of the options.

Returns

An integer, or a list of integers.

Examples

% text .co
> .co insert end "hello world\nline two"
> .co count 1.0 2.0
12

% text .co2
> .co2 insert end "a\nb\nc"
> .co2 count -chars -lines 1.0 end
6 3

Errors

% text .co3; .co3 count -bogus 1.0 2.0
bad option "-bogus" must be -chars, -displaychars, -displayindices, -displaylines, -indices, -lines, -update, -xpixels, or -ypixels
-errorcode NONE

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.1

See also