Bee Learnt Logo
Bee Learnt
FeatureBrowse allPricingAboutSupport
Bee Learnt

Bee Learnt gives South African Grade 10–12 learners a cleaner route from classwork to NSC readiness — with parents and tutors supporting the journey.

WhatsApp: 0685537312

Support email: admin@beelearnt.co.za

Learn
FeaturesBrowse subjectsPricing
Get started
Create accountSign inContact support
Company
About Bee LearntAdvertisingContact
Legal
Privacy policyTerms of serviceCookie policyAd choices

© 2026 Bee Learnt. All rights reserved.

CAPS aligned · Grades 10–12 · NSC ready

Privacy choices

Allow analytics and advertising services to help us understand site usage and measure campaigns.

Privacy Policy
  1. Subjects
  2. /
  3. Information Technology
  4. /
  5. Information Technology Grade 12 — Practical
  6. /
  7. Control flow and strings
  8. /
  9. String processing and safe indexing
Grade 12 · Practical

String processing and safe indexing

Control flow and strings · about 7 min

2 MIN READ
1 study sections · pause after each one and recall the key idea

For the ordinary Delphi strings used in these examples, character positions start at 1. Length returns the number of characters; Pos returns 0 when a substring is absent. Never use the result of Pos as a valid character position until you have checked it. Copy reads a substring; Delete and Insert modify a string. Establish whether a requirement counts letters, words or all characters, because spaces and punctuation change those results.

Normalising the comparison string to uppercase lets you compare A–Z consistently while retaining the original for display. A pangram contains every letter A–Z at least once; repeated occurrences do not compensate for a missing letter. An empty input must return false. This example deliberately tests the English alphabet, not every writing system.

Key points
  • Use Length, Copy, Pos and character indexing.
  • Normalise case when comparing.
  • Handle empty strings and missing delimiters.

Worked example: function IsPangram(const sText: string): Boolean; var cLetter: Char; sUpper: string; begin sUpper := UpperCase(sText); Result := True; for cLetter := 'A' to 'Z' do if Pos(cLetter, sUpper) = 0 then begin Result := False; Exit; end; end; The quick brown fox jumps over the lazy dog contains all 26 letters, so it returns True. Removing every z makes the Z check return position 0 and the function exits False. SysUtils supplies UpperCase.

COMMON MISTAKE

Counting 26 characters or 26 letters does not prove that all distinct letters occur. Accessing sText[1] is unsafe when Length(sText)=0.

Practice: How would you count vowels case-insensitively without counting spaces?

Answer: Loop from 1 to Length(sText), convert each character with UpCase, and increment only if the character is in ['A','E','I','O','U']. Initialise the count before the loop; empty text naturally produces zero.

Recap: Check bounds and missing delimiters; distinguish total occurrences from distinct membership.


Previous

Choosing loops and decision structures

Next

Delphi date and time functions