String Manipulation

GCSE Computer Science · Programming

Common operations

LEN("hello")            = 5            # length
"hello"[0]              = "h"          # index (zero-based)
"computer".SUBSTRING(0,4) = "comp"     # extract part
"data" + "base"         = "database"   # concatenation
UPPER("hi")             = "HI"
LOWER("Hi")             = "hi"
str(15)                 = "15"         # int → string
int("15")               = 15           # string → int

Worked example

name ← "Ada Lovelace"
OUTPUT LEN(name)        # 12  (the space counts!)
OUTPUT name[0]          # A
OUTPUT UPPER(name)      # ADA LOVELACE

Looping through a string

FOR i ← 0 TO LEN(word) - 1
    OUTPUT word[i]
NEXT i

Exam tip

Spaces and punctuation count towards length. Indexing usually starts at 0, so the first character is position 0 and the last is length − 1.

Don't understand a part?

Sign in and ask our AI tutor to explain any passage in plain English.

Try AI explanations →

More on Programming

Programming Fundamentals Selection and Iteration Arrays, Lists and Records Subroutines: Functions and Procedures

← All GCSE Computer Science notes