xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

Len()

Returns the number of items contained in an array, hash or string

Syntax

Len( <aArray> | <cString> | <hHash> ) --> nCount

Arguments

<aArray>
An array whose number of elements is determined.
<cString>
A character string whose number of characters is determined.
<hHash>
A hash whose number of key/value pairs is determined.

Return

The function returns the number of items stored in the passed parameter as a numeric value. When the passed parameter is empty (contains no items), the return value is zero.

Description

The function Len() accepts parameters of three different data types: Array, Character string and Hash. It returns the number of items stored in the passed parameter.

Return value of Len()
Data typeDescription
ArrayNumber of array elements in first dimension
Character stringNumber of characters
HashNumber of key/value pairs

The return value is zero, when an array has no elements, a string has no characters or a hash has no key/value pair.

Info

See also:Array(), Empty(), Hash(), LenNum(), LTrim(), RTrim()
Category: Array functions , Character functions , Hash functions
Source:rtl\len.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example shows return values of Len() with different data types

   PROCEDURE Main
      LOCAL aArray  := Directory( "*.prg" )
      LOCAL cString := "Hello World"
      LOCAL hHash   := { "A" => 1, "B" => 2, "C" => 3, "D" => 4 }

      ? "Array :" , Len( aArray  )           // result: 217
      ? "String:" , Len( cString )           // result:  11
      ? "Hash  :" , Len( hHash   )           // result:   4
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe