PAPER 2 • 2.2.1 Programming Fundamentals • STRING HANDLING

Do Now!

String handling lets a program inspect, extract and transform text. OCR gives you tools such as .length, .substring, .left, .right, .upper, .lower, ASC and CHR.

String handling diagram A visual comparing string slicing, case conversion and ASCII conversion. SLICING TEXT take part of a string left(i) right(i) TRANSFORM TEXT change or convert it upper lower ASC/CHR

Today's Big Idea

Different OCR string commands help for different jobs. Some commands take part of a string, some change its case, and some convert between characters and ASCII values.

.length Counts how many characters are in the string.
.substring Extracts a section using a start index and number of characters.
ASC / CHR Switches between a character and its numeric code.

Activity 1: Match the Key Terms

Drag each term into the correct definition.

.LENGTH
.SUBSTRING
.LEFT
.RIGHT
.UPPER
ASC
Term Definition
Gives the number of characters in a string.
Extracts part of a string from a start index.
Takes a chosen number of characters from the left.
Takes a chosen number of characters from the right.
Converts text into uppercase letters.
Converts a character into its ASCII number.

Activity 2: Which String Tool Fits Best?

Sort each prompt into the group that makes the most sense.

Showing the first 3 letters of a word.
Showing the last 2 letters of a filename.
Taking the middle part of "ComputerScience".
Creating a short code from the first 4 characters.
Turning a heading into CAPITAL letters.
Changing an email address to lowercase.
Changing "A" into its ASCII number.
Turning 33 into a character.

Take Part of a String

Change or Convert Text

Activity 3: Predict the Output

Use the code to decide what each program will print.

Predict 1

word = "robot"
print(word.length)

Predict 2

subject = "ComputerScience"
print(subject.left(4))

Predict 3

print(CHR(65))

Activity 4: Explain the Choice

Read the task below and explain which string command fits each part best.

Task Scenario

A school app stores the text "computer science". It needs to show the first four letters as a short code and then display the whole title in uppercase on a heading.

Think about the job each command does. .left(4) is good for taking the first four characters, while .upper is best for changing the whole string into capital letters.

Download PDF Evidence

Create a record of your starter activity responses.