DoRevision

String Surgeon

The string operations you can perform in code: finding the length, reading a position, taking a substring, joining strings, and converting between characters, codes and numbers.

⏱️ 16 min 🎯 14 activities
Best used for
Homework Intervention Mock preparation

Get the method right under pressure

Free interactive practice on the steps that lose marks under exam pressure.

Start revising free

What you'll cover

Cutting and joining text

A string is a piece of text, and programs constantly measure it, cut pieces out of it, and stick pieces together. Knowing the main string operations lets you pull a first name out of a full name, build a message, or check a password length. This module works through length, position, substring, concatenation and conversion.

String words to know

Learn these before you slice and join.

Reading against changing

Some operations just read a string; others make a new one.

Count from zero, name the operation

In the exam, remember the first character sits at position 0, so a string of n characters runs from position 0 to n minus 1. Off-by-one slips here lose marks. Name the operation you need: length to count, position to locate, substring to cut out, concatenation to join, and conversion to turn a string of digits into a number.

Match the operation

  • length
  • position
  • substring
  • concatenation
  • counts how many characters there are
  • finds where a character sits
  • takes a part out of a string
  • joins strings into one

Match the example

  • HELLO has 5 characters
  • H sits at position 0
  • taking ELL from HELLO
  • joining cat and fish into catfish
  • this is finding the length
  • this is reading a position
  • this is taking a substring
  • this is concatenation

Where is the first character?

In the string HELLO, at which position is the first character, the H?

  • Position 0
  • Position 1
  • Position 5
  • It has no position

True about strings

Select the TWO true statements about string operations.

  • Length gives the number of characters
  • Concatenation joins strings together
  • A substring must be the whole string
  • The first character is at position 1

Length of the join

The string cat has 3 characters and the string fish has 4 characters. When they are joined together, add the two lengths to find how many characters the result has. What is the answer?

Order the name-splitter

Put the steps of pulling a first name out of a full name in order, earliest first.

  • Find the position of the space
  • Take the substring before it
  • Store that as the first name
  • Use it in a greeting

Complete the rules

The _____ of a string is how many characters it has. The first character sits at position _____. Taking a part of a string is called a _____, and joining strings together is called _____.

length 0 substring concatenation code 1 sort division

Spot the new-string operations

Tap the TWO operations that produce a brand new string rather than just reading one.

  • taking a substring
  • concatenating two strings
  • finding the length
  • reading a position

Pick the operation

Read each task and choose the string operation needed.

  • You need to check that a password has at least 8 characters. Which operation do you use?
  • You want to join a first name and a surname into one full name. Which operation do you use?
  • You need just the year part from a date written as text. Which operation do you use?

Explain string operations

Explain the main string operations and how positions in a string are numbered.

  • Say what length and position each do
  • Explain the difference between a substring and concatenation
  • State where the first character sits and why off-by-one errors happen