String Handling Functions (LENGTH, SUBSTRING, UCASE, LCASE)

A STRING is a sequence of characters. A CHAR stores one character. Storage width depends on encoding; neither declaration is a promise of one byte.

Routine

Example

Result

LENGTH

LENGTH("River")

5

SUBSTRING

SUBSTRING("River",2,3)

"ive"

UCASE

UCASE("River")

"RIVER"

LCASE

LCASE("RiVER")

"river"

UCASE and LCASE work with strings as well as characters. This course and its runner use position 1 for the first character in SUBSTRING; check the convention stated in another system or question. The third argument is the number of characters, not the ending position.

Worked username

For first name Mira and surname Santos, SUBSTRING("Mira",1,1) gives M. Concatenate using &: M & Santos gives MSantos. LCASE converts the whole result to msantos. Converting only the first character would leave the surname's capitals unchanged.

Independent practice

Trace SUBSTRING("COMPUTER",3,4), then apply LCASE. The extracted string is MPUT and the lowercase result is mput. Now use different names in the username exercise.

AI Socratic Tutor

All-Access
Sign in or create an account. AI Tutor is an All-Access benefit.
Sign Up

Need guidance? Ask a question or use the hint below.

AI Socratic Tutor is an All-Access Benefit

Unlock step-by-step Socratic hints, algorithm trace table walkthroughs, and error diagnostics for every Cambridge exercise.

You're chatting with an AI tutor, not a person. AI can make mistakes, so double-check its answers.

Exam-Style Check: Cambridge SUBSTRING Evaluation

• Multiple Choice
+25 XP
Question

Use this course’s 1-based string indexing. In Cambridge pseudocode, what string value is returned by the expression: SUBSTRING("ALGORITHM", 3, 4)?

All-Access Required

Interactive exercises for Module 2 and beyond require an active plan.