Jump to content

Len (programming): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
Line 1: Line 1:
{{Unreferenced|date=December 2009}}
{{Unreferenced|date=December 2009}}
Many common [[programming language]]s operate on [[string (computer science)|strings]] using [[String functions (programming)|string functions]]. One of the major string functions '''Len''', returns the length of a specific string.
Many common [[programming language]]s operate on [[string (computer science)|strings]] using [[String functions (programming)|string functions]]. One of the major string functions '''Len''', returns the length of a specific string.
6710864

This function is called '''Len''', which stands for [[length]], in the [[BASIC programming language]] and its derivatives such as [[Visual Basic]]. It is called [[strlen]] in the [[C programming language]] and its derivatives such as [[PHP]]. In some other programming languages, the entire word "length" is written out as the name of the function. ''For other languages see [[String functions (programming)|string functions]]. ''
This function is called '''Len''', which stands for [[length]], in the [[BASIC programming language]] and its derivatives such as [[Visual Basic]]. It is called [[strlen]] in the [[C programming language]] and its derivatives such as [[PHP]]. In some other programming languages, the entire word "length" is written out as the name of the function. ''For other languages see [[String functions (programming)|string functions]]. ''



Revision as of 21:01, 30 July 2010

Many common programming languages operate on strings using string functions. One of the major string functions Len, returns the length of a specific string. 6710864 This function is called Len, which stands for length, in the BASIC programming language and its derivatives such as Visual Basic. It is called strlen in the C programming language and its derivatives such as PHP. In some other programming languages, the entire word "length" is written out as the name of the function. For other languages see string functions.

Usage in Other Languages

To see a list of usages in other languages see the length section in

Usage in Visual Basic

In Visual Basic, the prototype of the Len function is as follows:

 Function Len (ByVal Str As String)

An example below shows an example of the use of Len function.

Sub Main()
    Dim Str As String
    Dim Int As Integer
    Str = InputBox("Enter a string")
    Int = Len(Str)
    MsgBox(CStr(Int))
End Sub

This function reads a string from an input box and outputs its length.

For example, the input "Hello!" will output 6.

Usage in Python

In Python, len() can be used to indicate the length of a string:

>>> something = 'Wikipedia'
>>> len(something)
9

where the word "Wikipedia" clearly has 9 letters. Consider also the example of "I am John"

>>> len('I am John')
9

because "I am John" clearly has 9 characters (keep in mind that spaces are counted as well).

The function len() can also be used to find the size (i.e. number of elements) of lists, tuples, dictionaries, sets, and other sequence types (any object that implements a __len__() method can be used). Here the list p includes 3 entries:

>>> p = ['Wikipedia', 'Wiktionary', 'Wikibooks']
>>> len(p)
3

Usage in Go

In Go, len() can be used to obtain the length of a string, array, or slice, the number of keys in a map, or the number of elements queued in a channel.