aimnova.
DashboardMy LearningPaper MasteryStudy Plan

Aimnova site navigation

Stay in the loop

Get the latest study resources and updates

New features, study tips and exam insights — straight to your inbox.

IB Diploma

  • IB Past Papers
  • IB Study Notes
  • IB Question Bank
  • IB Mock Exams
  • IB Revision

IB Subjects

  • IB Math AA
  • IB Math AI
  • IB Economics
  • IB Business Management
  • IB Physics
  • IB Biology
  • View all IB subjects→

IB Past Papers

  • IB Math AA HL Past Papers
  • IB Math AA SL Past Papers
  • IB Math AI HL Past Papers
  • IB Math AI SL Past Papers
  • IB Economics HL Past Papers
  • IB Economics SL Past Papers
  • IB ESS Past Papers
  • View all past papers→

Study Resources

  • Study Notes
  • Question Bank
  • Mock Exams
  • Flashcards
  • Revision Guide
  • Exam Skills
  • Command Terms
  • Grade Calculator
  • Exam Timetable 2026

Aimnova

  • Features
  • Pricing
  • For Schools
  • For Parents
  • About Us
  • Blog
  • Contact
aimnova.

AI-powered study platform for smarter revision, past-paper analysis and examiner-style feedback.

TermsPrivacyCookies·© 2026 Aimnova. All rights reserved.8afc4e3

Aimnova is not affiliated with or endorsed by the International Baccalaureate Organization (IB).

NotesComputer ScienceTopic 6.1Substrings
Back to Computer Science Topics
6.1.25 min read

Substrings

IB Computer Science • Unit 6

AI-powered feedback

Stop guessing — know where you lost marks

Get instant, examiner-style feedback on every answer. See exactly how to improve and what the markscheme expects.

Try It Free

Contents

  • A string is a sequence of positions
  • Taking a slice
  • Doing something useful with it
  • Exam-style question
The big idea: A string is characters in order, and every one has a position.

A substring is a run of those positions taken out as a string of its own.
Positions start at 0: The first character is at position 0, not 1.

So in "HELLO", H is 0, E is 1, L is 2, L is 3 and O is 4. Nearly every substring error starts here.

Free preview

This is the free notes preview

You're reading the free notes. Aimnova Pro unlocks the full study experience — and you can try it with your first topic free to keep:

  • FlashcardsLock in vocabulary and key terms with spaced repetition.
  • Practice questionsAnswer exam-style questions and get instant AI marking.
  • Mock exams & past-paper vaultSit full mocks and see exactly how examiners award marks.
  • Personalised study planA daily plan built around your exam date and weak areas.
Start Studying Free Full access to Aimnova Pro · cancel anytime
The end position is not included: text[2:5] gives the characters at positions 2, 3 and 4 — not 5.

That sounds awkward until you notice the useful consequence: the length of the slice is simply end minus start. 5 − 2 = 3 characters.

Taking part of it

  • text[a:b] — from a, up to but not including b
  • text[:b] — from the start
  • text[a:] — to the end
  • text[-1] — the last character, counting back

Finding and measuring

  • len(text) — how many characters
  • text.find("x") — the position where x starts, or -1
  • "x" in text — True or False
  • Find before you slice, when you do not know the position

Changing it

  • text.upper() and text.lower()
  • text.replace(a, b) — swap one run for another
  • text.split(",") — break into a list at each comma
  • All of these return a new string; the original is unchanged
Strings do not change in place: text.upper() returns an uppercase copy — it does not modify text.

If you want to keep it, you must assign it: text = text.upper(). Forgetting is a very common bug.

Practice with real exam questions

Answer exam-style questions and get AI feedback that shows you exactly what examiners want to see in a full-marks response.

Try Practice FreeYour first topic is free to keep • No credit card required
Find the position, then slice: Most real problems do not give you the position. You find it first, then use it.

Splitting an email at the @ means finding the @, then slicing either side of it.
1

Why +1 after find

2

Always handle not found

How this is tested — you must get the positions right — counting from 0, and excluding the end. It comes up two ways:

Paper 2 — working with code

  • Construct code to extract or build a substring, 3-5 marks
  • State what a given slice produces
  • Explain an off-by-one error

Paper 2 — the algorithmic-thinking question

  • Reason about positions with no code shown
  • Say what a described manipulation would produce
The classic trap: Off by one. Positions start at 0, and the end of a slice is not included. Write the positions above the string on your paper before you answer anything.
IB-style questionConstruct[5 marks]

A product code looks like "BK-2026-1147". Write code to extract the type (BK), the year (2026) and the number (1147), without assuming fixed positions.

Model answer plan

See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.

Claim your free topic

Try an IB Exam Question — Free AI Feedback

Test yourself on Substrings. Write your answer and get instant AI feedback — just like a real IB examiner.

the substring of 'COMPUTER' from position 4 to position 6, counting the first character as position 1. [2 marks]

Related Computer Science Topics

Continue learning with these related topics from the same unit:

6.1.1Variables and data types
6.1.3Exception handling
6.1.4Debugging
6.2.1Static vs dynamic structures
View all Computer Science topics

Improve your exam technique

Command terms, paper structure, and mark-scheme tips for Computer Science

Previous
6.1.1Variables and data types
Next
Exception handling6.1.3

24 practice questions on Substrings

Students who practiced this topic on Aimnova scored 82% on average. Try free practice questions and get instant AI feedback.

Try 3 Free QuestionsView All Computer Science Topics