String handling
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
LENGTH counts characters
LENGTH(s)gives how many characters are in a string.
OUTPUT LENGTH("hello") // → 5
UCASE and LCASE change case
UCASE(s)makes a string all CAPITALS.LCASE(s)makes it all lower case.
OUTPUT UCASE("abc") // → ABC
OUTPUT LCASE("HeLLo") // → hello
SUBSTRING takes part of a string
SUBSTRING(s, start, length)copies part of a string.- The first character is position 1 (not 0).
OUTPUT SUBSTRING("Computer", 1, 4) // → Comp
Joining with &
- The
&operator joins two strings together.
OUTPUT "Cam" & "bridge" // → Cambridge
Common mistakes
- Learn the exam's function names:
LENGTH,SUBSTRING,UCASE,LCASE. - String positions in pseudocode often start at
1, not0.
Now you try
- Use the string functions above.
- Press Check answer to test it.
Read a word, then output how many characters it has with LENGTH. For input hello, output 5.
Click Run to see the output here.
Read a word and output it in CAPITALS with UCASE. For input cat, output CAT.
Click Run to see the output here.
Read a word and output its first 3 letters with SUBSTRING (start at 1, length 3). For input Computer, output Com.
Click Run to see the output here.