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

- **Track:** Cambridge IGCSE™ Computer Science (0478 / 0984) (CAMBRIDGE IGCSE 0478)
- **Module:** Section 8: Programming Concepts & File Handling
- **Estimated Duration:** 10 minutes
- **Access:** Open Theory (All-Access for Interactive IDE &amp; Autotests)

---

## Theory & Conceptual Background

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.

---

## Interactive Exercises & Autotest Specifications

### Exercise 1: Exam-Style Check: Cambridge SUBSTRING Evaluation (Multiple choice, 25 XP)

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

**Options:**
- **A**: &quot;ALGO&quot;
- **B**: &quot;ORIT&quot;
- **C**: &quot;GOR&quot;
- **D**: &quot;GORI&quot;


**Autotest Expectations:**
- **Correct substring result chosen**: `selection_match` -> Expected: `opt_gori`

### Exercise 2: Application: Whole-string routines (Fill in blank, 30 XP)

**Instructions:**
Work out each answer before submitting. Write UCASE("Good Day") without quotation marks: Write LCASE("AlI") without quotation marks: LENGTH("Paper 2") is:


**Starter Code:**
```text
{"prompt":"Application: Whole-string routines","template":"1. Write UCASE(\"Good Day\") without quotation marks: [blank_1]\n2. Write LCASE(\"AlI\") without quotation marks: [blank_2]\n3. LENGTH(\"Paper 2\") is: [blank_3]","blanks":[{"id":"blank_1","case_sensitive":true},{"id":"blank_2","case_sensitive":true},{"id":"blank_3"}],"word_bank":["GOOD DAY","good day","ali","ALI","7","8","6"]}
```


### Exercise 3: Independent Practice: Lowercase usernames (Pseudocode, 30 XP)

**Instructions:**
Read a non-empty first name and surname. Output a username consisting of the first character of the first name followed by the whole surname, all lowercase.

Write a complete program. Read inputs in the stated order. Output only the requested results, one per line, without input prompts. Test with your own values before submitting.


**Starter Code:**
```text
// Plan your solution, then write your program.

```

**Autotest Expectations:**
- **Mixed case**: `test_case` -> Expected: `{&quot;inputs&quot;:[&quot;Mira&quot;,&quot;SANTOS&quot;],&quot;output&quot;:&quot;msantos&quot;}`
- **Another name**: `test_case` -> Expected: `{&quot;inputs&quot;:[&quot;ELI&quot;,&quot;Chen&quot;],&quot;output&quot;:&quot;echen&quot;}`

