String length
From Coderwiki
More actions
Most programming languages (with the notable exception of C) have a way to check the number of elements in a collection.
As strings are just collections, this method applies to strings too.
Null termination
In many languages, strings are null terminated. This means that if you have a 5-character string, it will actually be a collection of 6 elements (as it includes the \0 null-terminator).
When checking a string's length in most programming languages, this null terminator is ignored, so the length will come out as 5 in the example above.
Checking a string's length
In most programming languages, there is either a function, method or field which returns the length of the string.
Guides for specific programming languages: