Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

AC 2.3: Joining and slicing text in cells

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

55 minutes

One code, four facts

A pupil code like Y09-AMY-03 packs in the year, the initials and the form number. The office wants each fact in its own column. It also wants first name and last name joined into one.

Retyping hundreds of codes is slow. Text formulas take them apart and join them up.

Key words

WordWhat it means
CONCATENATEjoins pieces of text into one piece
LEFTtakes a number of characters from the start of text
RIGHTtakes a number of characters from the end of text
MIDtakes characters from the middle, from a start place for a length
Characterone letter, digit, space or symbol
Stringa piece of text, in programming
Positionthe place of a character, counted from 1 in a spreadsheet

The cells students fill in are left blank in this preview.

By the end of this lesson

Note

I can use CONCATENATE, LEFT, RIGHT and MID to join and split text.

Starter

Have a go

Starter

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

No spreadsheet here

Important

This platform has no spreadsheet program. Here the cells are a table and the formula is shown as text. You do the same job with code. On site you use a real spreadsheet program.

The pupil codes as cells

RowA codeB first nameC last name
1Y09-AMY-03AmyReed
2Y07-BOJ-11BoJones
3Y11-CYD-07CyDean

The cells students fill in are left blank in this preview.

Four text formulas, row 1

FormulaGivesWhy
`=CONCATENATE(B1," ",C1)`Amy ReedFirst name, a space, last name
`=LEFT(A1,3)`Y09The first 3 characters
`=RIGHT(A1,2)`03The last 2 characters
`=MID(A1,5,3)`AMYStart at place 5, take 3

The cells students fill in are left blank in this preview.

Try it: the same jobs in Python

Code: python
code = "Y09-AMY-03"
print(code[0:3])          # LEFT 3
print(code[len(code) - 2:len(code)])   # RIGHT 2
print(code[4:7])          # MID start 5, length 3
print("Amy" + " " + "Reed")  # CONCATENATE

# Python counts from 0, a spreadsheet counts from 1.
# That is why MID start 5 is code[4].

Try it: and in SQL

Code: sql
SELECT code,
  substr(code, 1, 3) AS year_part,
  substr(code, 5, 3) AS initials,
  first_name || ' ' || last_name AS full_name
FROM pupils;

-- substr(text, start, length) counts from 1, like MID.
-- The two bars join text, like CONCATENATE.

The lesson goes on

5 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.