AP CSP Day 35: String Manipulation
Share
Big Idea 3
Day 35 Practice
Focus: String Manipulation
Practice Question
Consider the following code segment:
text ← "COMPUTER"
result ← SUBSTRING(text, 4, 7)
DISPLAY(result)Why This Answer?
SUBSTRING(text, 4, 7) extracts characters from position 4 to position 7 inclusive (positions start at 1). C=1, O=2, M=3, P=4, U=5, T=6, E=7, R=8. So positions 4-7 = PUTER.
Why Not the Others?
A) This is SUBSTRING(text, 1, 4).
B) This is SUBSTRING(text, 1, 5).
C) This is SUBSTRING(text, 4, 6).
Common Mistake
Watch Out!
Forgetting that SUBSTRING end parameter is inclusive. SUBSTRING(text, 4, 7) includes position 7.
AP Exam Tip
Check exam reference: AP CSP SUBSTRING has inclusive end. Always verify parameter behavior.