A computer program is a sequence of instructions written to perform a specified task with a computer. A computer requires programs to function, typically executing the program's instructions in a central processor. The program has an executable form that the computer can use directly to execute...
In formal languages, which are used in mathematical logic and theoretical computer science, a string is a finite sequence of symbols that are chosen from a set or alphabet....
In computer science, a subroutine is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code....
In geometric measurements, length most commonly refers to the longest dimension of an object.In certain contexts, the term "length" is reserved for a certain dimension of an object along which the length is measured. For example it is possible to cut a length of a wire which is shorter than wire...
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
BASIC is a family of general-purpose, high-level programming languages whose design philosophy emphasizes ease of use - the name is an acronym from Beginner's All-purpose Symbolic Instruction Code....
Visual Basic is the third-generation event-driven programming language and integrated development environment from Microsoft for its COM programming model...
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....
PHP is a general-purpose server-side scripting language originally designed for web development to produce dynamic web pages. For this purpose, PHP code is embedded into the HTML source document and interpreted by a web server with a PHP processor module, which generates the web page document...
. In some other languages, the full word length is written out as the name of the function. For other languages see Comparison of programming languages (string functions).
Use in other languages
To see a list of uses in other languages see the length section in
Visual Basic is the third-generation event-driven programming language and integrated development environment from Microsoft for its COM programming model...
, the prototype of the Len function is this:
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.
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...
, len can be used to denote 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
Space (punctuation)
In writing, a space is a blank area devoid of content, serving to separate words, letters, numbers, and punctuation. Conventions for interword and intersentence spaces vary among languages, and in some cases the spacing rules are quite complex....
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
Go is a compiled, garbage-collected, concurrent programming language developed by Google Inc.The initial design of Go was started in September 2007 by Robert Griesemer, Rob Pike, and Ken Thompson. Go was officially announced in November 2009. In May 2010, Rob Pike publicly stated that Go was being...
, 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.
The source of this article is wikipedia, the free encyclopedia. The text of this article is licensed under the GFDL.