Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 11:21, 15 August 2025 by Dylan (talk | contribs) (add: C Sharp language-specific guide)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

edit edit source

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

edit edit source

In most programming languages, there is either a function, method or field which returns the length of the string.

Guides for specific programming languages: