GCSE · Computer Science · AQA · Spec 8525
String position
Ask a computer where the 's' is in 'mississippi' and its answer surprises almost everyone. Make your guess, then watch it search.
Computer Science · Strings
Where is the first 's' in 'mississippi'?
The program asks for the position of 's'. Step through the search one character at a time and watch where it stops.
Before you press Next, make a guess: what number will this program output?
1 word ← 'mississippi'2 where ← POSITION(word, 's')3 OUTPUT where
| index | character | match? | where |
|---|---|---|---|
Output
Step 1: word holds 11 characters. Each one sits in a numbered slot, and the very first slot is number 0.
Press Next to move the search along one character. Did your guess match the output?
WHAT YOU'VE LEARNED
A quick recap of today's lesson.
Count from 0. Stop at the first match.
What you need to know
- Position takes a string and a character and gives back a whole number: the index where that character first appears.
- In the pseudo-code here, and in Python, Java, C# and JavaScript, indexes start at 0. The first character is index 0, the second is index 1, and so on. (A few languages count from 1, so check the language you're using.)
- The search stops at the first match. Any later copies of the character are ignored.
- Store the result in a variable, e.g. where ← POSITION(word, 's'), so the rest of the program can use it.
The big picture
Position is a string handling operation. You give it a string and a character, and it gives back a number: the index of the first place that character appears. In the pseudo-code used here, and in languages such as Python, Java, C# and JavaScript, indexes count from 0, so the first character is at index 0. The search stops at the first match, so later copies of the character are ignored. Store the result in a variable and the rest of your program can use it.
Key points
Worked example
Problem
A program stores code ← 'AB-77-31'. It then runs dash ← POSITION(code, '-') followed by OUTPUT dash + 1. What does the program output?
⚠ Watch out
Answering with the 'which letter is it' count. When counting from 0, the 4th character of a string is at index 3, not 4.
Memory hook
Finger on the first letter, say ZERO. Slide right, counting, and stop at the very first match.
Check yourself
What does POSITION('cheese', 'e') give back, and why isn't it 3 or 5? (Answer: 2. The search stops at the first e, so the others are never reached.)
Flashcards
(7)What does the position operation give back?
With zero-based indexing, what is the index of the first character in a string?
A character appears three times in a string. Which one does position report?
With zero-based indexing, the 5th character of a string is at which index?
What is POSITION('banana', 'n')?
Write pseudo-code that stores where 'x' first appears in text, in a variable called pos.
Why store the result of POSITION in a variable?
Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.
Learning with Lightbulb is opening soon
You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.
Keep me postedMore AQA GCSE Computer Science topics
How this lesson was checked. This AQA GCSE Computer Science (specification 8525)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 29 September 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.