tcountn


The tcountn function returns the count of numeric values in a general lua table that may contain non-numeric values, named keys, and sub-tables. Only numeric values found in the table are used in the total. If the table is an array, then the total should equal the total number of indices in the array. For a general table containing string and other values, the count will be less than the number of elements in the table.

Syntax

nCount = tcountn( tbl )

bullet.gif    tbl is a general lua table.

bullet.gif    nCount is the count of the numeric values in the table.

Example

The following script returns the number of numeric values in an ugly, complex table. Note that the string "24" is not counted as a numeric value.

t = { { 1, "c", a=-12, dar={17,"v"} }, {-15, "24", 3, 5} }

 

n = tcountn(t)

-- get the count

Printf("Count = %d\n", n )

-- result: Count = 6

Related Topics

Table and Array Functions, ismultidim


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics, Inc. All Rights Reserved.