AQA · GCSE · Computer Science
Course version: 8525 · Version from Sept 2020
String handling operations in a programming language: position
This row names one string handling operation in AQA 8525 section 3.2.8: finding the position of a character or substring within a string.
Checked against the AQA 8525 specification (opens in a new tab) on .
- Point 2 of 11
Study notes
From the checked teaching notes for this specification point.
The idea
This row names one string handling operation in AQA 8525 section 3.2.8: finding the position of a character or substring within a string. The skill is to know that a position (often called an index) locates where a piece of text occurs, and to use the operation your language provides. In Python, "computer".find("put") returns 3, because counting starts at 0: c is 0, o is 1, m is 2, p is 3. Many languages count from 0, but some, such as those using 1-based indexing, start at 1, so always check your language. If the substring is absent, the operation usually returns a sentinel such as -1 in Python. A typical use is checking whether a word appears in a sentence before acting on it. Practise predicting the returned value, then confirm it by running the code.
What earns the marks
- States that the position operation locates a character or substring within a string and returns an index.
- Recognises that indexing commonly starts at 0 in languages such as Python, so the first character is at position 0.
- Applies the operation correctly to a given string, for example finding the position of a substring and returning the expected index.
- Explains that a not-found result is signalled by a special value, such as -1 in Python, rather than an error.
- Notes that indexing conventions differ between languages, so the language in the question must be checked.
Common mistakes and how to put them right
Counting the first character as position 1 in a 0-based language.
Put it right: Start counting at 0 and re-check the returned index.
Confusing the position of a substring with its length.
Put it right: Separate the two operations and test each one.
Assuming a missing substring causes a crash.
Put it right: Test a search for text that is absent and observe the sentinel value returned.
Forgetting that spaces count as characters.
Put it right: Count every character, including spaces, when predicting an index.
Exam tips
- Write out the string with an index number under each character before you answer, so you do not miscount.
- Check whether the question's language uses 0-based or 1-based indexing before giving a position.
- If a substring is not present, state the value the operation returns in that language rather than saying it errors.
Try the lesson
The start of the String handling operations in a programming language: position lesson, made from checked teaching notes for this specification point.
Have a go first
In many programming languages, string positions are counted starting from 0. For the string "hello", what position is the character "h" at?
There is more to this lesson
The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge
Test your understanding of String handling operations in a programming language: position
Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.
A week of Premium from your first lesson · Then the free plan continues · No card, no charge