String Handling

Test yourself on String Handling with exam style questions, marked instantly.

Flashcards that come back just before you would forget them.

A revision plan that remembers what you know and shows what to do next.

See which topics you have nailed and which need another look.

Quiz yourself on String HandlingGet your flashcardsBuild my revision planTrack my progress

Working with Text

Strings are everywhere - names, addresses, passwords, messages. String handling is the art of manipulating text. Need to extract the first 3 characters? Check if an email contains "@"? Convert to UPPERCASE? Concatenate first name and surname? These operations are essential for any program that deals with text!

The string "Hello World" drawn as 11 boxes, one character each, numbered from 0 to 10, with a bracket marking a length of 11. The space at position 5 is marked with an open box symbol. Below are nine operations, each with an example: length, LEN("Hi Al") = 5; substring, "Hello" positions 0 to 2 gives "Hel"; upper case, "hi" gives "HI"; lower case, "HI" gives "hi"; join, "Hi " + "Al" gives "Hi Al"; character to code, "A" gives 65; code to character, 65 gives "A"; text to number, "42" gives 42; number to text, 42 gives "42".

The open box symbol marks a space, and a space counts as a character, so "Hello World" has length 11. The figure counts substring positions 0 to 2, which gives "Hel". In OCR style that is "Hello".substring(0, 3), because OCR takes a start position and a number of characters. The figure writes length as a plain label; OCR writes .length. Upper and lower case conversion is on OCR and Edexcel. Character to code and code to character are on AQA and OCR (OCR writes ASC and CHR). Text to number and number to text are on AQA and OCR.

GCSE String Operations

Operation Pseudocode Example Result
Length string.length "Hello".length 5
Substring string.substring(start, length) "Hello".substring(0, 2) "He"
Uppercase string.upper "Hello".upper "HELLO"
Lowercase string.lower "Hello".lower "hello"
Concatenation string1 + string2 "Hi" + " " + "there" "Hi there"
ASCII conversion ASC(char), CHR(code) ASC("A"), CHR(65) 65, "A"
Text to number, number to text int(string), str(number) int("42"), str(42) 42, "42"

Deep Dive: String Indexing

Strings are 0-indexed (first character is position 0):

text = "HELLO"
// Index: 0 1 2 3 4
// Char:  H E L L O

text.substring(0, 1) = "H"
text.substring(1, 3) = "ELL"
text[2] = "L"

Memory Trick

ASC = ASCII code (letter → number)
CHR = CHaRacter (number → letter)
Substring(start, length) = START where, take LENGTH chars

Exam Tips

  • 0-indexed: First character is at position 0
  • Substring: substring(start, length) not substring(start, end)
  • Common mistake: Forgetting strings are immutable - operations return new strings

Make this stick

Signing in gives access to all PrepWise features.

PrepWise is a trading name of A3M Quality Solutions Limited, registered in England and Wales, company number 14959172. Registered office: 202 Stroud Road, Gloucester, GL1 5LA. ICO registration ZC267069.