OCR · GCSE · Computer Science
Course version: J277 · Version from Sept 2022
Additional programming techniques: The use of basic string manipulation
Strings are sequences of characters, and basic string manipulation means extracting, combining, measuring and altering text.
- Point 1 of 7
- 4 key terms
Study notes
From the checked teaching notes for this specification point.
The idea
Strings are sequences of characters, and basic string manipulation means extracting, combining, measuring and altering text. Common operations include finding length with len("Hello") giving 5, joining strings with concatenation such as "Hello" + " " + "World", extracting a substring by slicing, for example "Computer"[0:3] giving "Com", and converting case with upper() or lower(). You can also search for a character or substring using find() or in, replace text with replace(), and split a string into parts. Indexing usually starts at 0, so the first character is at position 0. These techniques are used to validate input, format output, search records and process user responses. When manipulating strings, remember that they are immutable: operations return a new string rather than changing the original.
What earns the marks
- Uses len() to find the number of characters in a string, e.g. len("OCR") returns 3.
- Joins strings using concatenation, e.g. forename + " " + surname, and explains that both operands must be strings.
- Extracts part of a string using slicing or substring, e.g. "Computer"[0:3] returns "Com".
- Converts case using upper() or lower(), e.g. "Yes".lower() returns "yes".
- Searches within a string using find() or in, e.g. "cat" in "catalogue" returns True.
- Replaces characters or substrings using replace(), e.g. "2024".replace("4", "5") returns "2025".
- Explains that string indexing commonly starts at 0 and that strings are immutable.
Common mistakes and how to put them right
Using 1-based indexing when the language uses 0-based indexing.
Put it right: Check the first character position and adjust slices accordingly.
Trying to change a string in place, such as name[0] = "J".
Put it right: Build a new string, e.g. "J" + name[1:].
Concatenating a string and a number without casting, e.g. "Score.
Put it right: Cast with str(10) first.
Confusing len() with the last index.
Put it right: For a string of length n, valid indices are 0 to n - 1.
Exam tips
- Trace string operations on paper, writing the value after each step and counting characters carefully.
- When asked to manipulate a string, state the operation and show the result, e.g. slice, concatenate, change case.
- Check whether the question expects a single expression or a short sequence of statements, and keep code readable.
- Use quotation marks consistently and avoid mixing single and double quotes incorrectly.
Try the lesson
The start of the Additional programming techniques: The use of basic string manipulation lesson, made from checked teaching notes for this specification point.
Have a go first
A variable word holds the string "Computer". What is the result of word.length?
Listen
Strings are sequences of characters, and basic string manipulation means extracting, combining, measuring and altering text. Common operations include finding length with len("Hello") giving 5, joining strings with concatenation such as "Hello" + " " + "World", extracting a substring by slicing, for example "Computer"[0:3] giving "Com", and converting case with upper() or lower(). You can also search for a character or substring using find() or in, replace text with replace(), and split a string into parts. Indexing usually starts at 0, so the first character is at position 0. These techniques are used to validate input, format output, search records and process user responses. When manipulating strings, remember that they are immutable: operations return a new string rather than changing the original. A strong answer earns marks for these points. Uses len() to find the number of characters in a string, e.g. len("OCR") returns 3. Joins strings using concatenation, e.g. forename + " " + surname, and explains that both operands must be strings. Extracts part of a string using slicing or substring, e.g. "Computer"[0:3] returns "Com". Converts case using upper() or lower(), e.g. "Yes".lower() returns "yes". A common slip: Using 1-based indexing when the language uses 0-based indexing. Instead, check the first character position and adjust slices accordingly. Exam tip: Trace string operations on paper, writing the value after each step and counting characters carefully.
Key words
Say what each word means before you turn the card.
Concatenation
Try answering aloud or in your head before turning the card.
Slicing
Try answering aloud or in your head before turning the card.
Immutability
Try answering aloud or in your head before turning the card.
Indexing
Try answering aloud or in your head before turning the card.
See every definition
- Concatenation
- Joining strings together, such as "Hello" + " " + "World", where both operands must be strings.
- Slicing
- Extracting a substring, for example "Computer"[0:3] giving "Com".
- Immutability
- Operations return a new string rather than changing the original, so strings cannot be changed in place.
- Indexing
- Position of a character in a string, usually starting at 0, so the first character is at position 0.
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 Additional programming techniques: The use of basic string manipulation
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