I found a couple of answers online but I don't quite understand why the answer is right:
The length of a string is:
If a string has no characters, then its length is 0.
Otherwise, the length of the string is 1 + length of the tail
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It only takes a minute to sign up.Sign up to join this community
Strings are concatenations of characters. Hence, any non-empty string $w$ has a first character $x$ and can be written as $w = x w'$, where $w'$ is the tail string. It follows from the definition of a string's length that $|w| = |x w'| = |x| + |w'| = 1 + |w'|$.