← Computer Science

String Manipulation

A string is just an ordered list of characters, and once you can measure it and pull pieces out of it you can do real work like validating passwords or splitting a name. In this lesson we use the Cambridge pseudocode string functions LENGTH, SUBSTRING, UCASE and LCASE, plus the & operator for joining strings together.

Slide 1 / 4

A string is an indexed sequence of characters

A string: characters in order, counted from 1H1E2L3L4O5"HELLO" holds H, E, L, L, O at positions 1 to 5
  • A string is a sequence of characters stored in order, for example "HELLO" holds H, E, L, L and O.
  • Each character has a position, and in Cambridge pseudocode positions are counted from 1, so in "HELLO" the H is at position 1 and the O is at position 5.
  • Spaces, digits and punctuation are characters too, so "CS 2" is four characters: C, S, a space, then 2.
  • Because the characters are in a fixed order we can measure the whole string or reach in and take out a part of it.

Check you've got it

0/4

1. Which string function returns the number of characters in a string?

2. What does SUBSTRING("COMPUTER", 4, 3) return?

3. What is the result of the expression "RE" & "VISE"?

4. A password must be at least 8 characters long. Which expression is TRUE when the password is too short?

Practise exam-style questions on this

Type your answer, see your mark against the mark scheme in seconds. Free, 5 a day.

Start practising →

Teaching this topic?

Mark your whole class's answers and see who's stuck, for £19 a month.

See the class plan →

Free revision content. Multiple-choice answers are marked instantly. Written answers are marked by AI on /free-mark. Independent, not endorsed by Cambridge International.