StringLength

StringLength["string"]

gives the number of characters in a string.

Details

  • StringLength counts special characters such as as single characters, even if their full names involve many characters.
  • StringLength[{s1,s2,}] gives the list of lengths of each of the si.

Examples

open allclose all

Basic Examples  (1)

Find the number of characters in a string:

Scope  (3)

Find lengths of all strings in a list:

StringLength treats special characters just like ordinary ones:

Newlines count as one character:

Applications  (1)

Find the growth rate of a string substitution system:

Properties & Relations  (1)

The empty string has zero length:

Possible Issues  (2)

Formatting constructs are included in giving lengths of formatted strings:

StringLength counts every character as length 1, regardless of the length of its full name:

Introduced in 1988
 (1.0)
 |
Updated in 1996
 (3.0)
2003
 (5.0)
2004
 (5.1)