Skip to main content
AP CSP course

C23 · Topic 3.4 · 40 minutes · AAP-2.D

Strings and text values

By the end you can:

  • Distinguish text digits from numerical values.
  • Trace exact concatenation.
  • Account for spaces as characters.

Before this lesson: topics 3.1.

String
A sequence of characters used as text.
Concatenation
Joining text values in order without adding implied separators.

Understand

A string represents text even when its characters are digits. Joining “2” and “7” as text produces “27”, not the sum 9. Interpret an operation according to its contract and the kind of values supplied. A room code may need leading zeros preserved, unlike a numerical count used in arithmetic.

Concatenation joins the characters exactly in order. It does not insert a space unless one argument contains a space or the algorithm adds one. When explaining a text output, show quoted strings or otherwise make spaces visible so an apparently minor difference is testable.

Worked example

concat joins its two arguments exactly. Build a label from “Room ”,“2” and “7”.

label ← concat("Room ", concat("2", "7"))
  1. The inner concatenation gives “27”.
  2. The first argument includes one trailing space.
  3. The full result is “Room 27”, not “Room 9”.

Explore each concept

Choose a concept, change its inputs and follow the explanation. Each example models the stated rule or scenario; completing it is practice rather than evidence of mastery.

  • Text digits versus numbers
  • Concatenation and length
  • Literal spaces and leading zeros
Open this example on its own

Change it · step through · explain

Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.

Ready · Make a prediction

Ready to explore: Join exact strings and preserve spaces
  1. Left text (max 30 characters)007Waiting
  2. Right text (max 30 characters)2Waiting
  3. SeparatornoneWaiting

Ready to explore: Join exact strings and preserve spaces

Why: Change an input, predict the first effect, then advance one step.

Try this: Change one input or choose another listed case. Predict the effect, reset and compare the states and governing rule.

Step through and experiment

Change it · step through · explain

Change an input, predict what will happen, then advance one step. Read why the state changes, reset and experiment. This fixed teaching model does not save progress or award XP.

Ready · Make a prediction

Ready to experiment
  1. Input 1PLANETWaiting
  2. Input 22Waiting
  3. Input 33Waiting

Ready to experiment

Why: Predict the first change, then advance one step.

Try this: Try count 0, a count beyond the end, and start one past the last character.

Check a misconception

Claim: Text containing digits is automatically added numerically.

A text operation acts on characters unless a conversion or different contract is explicitly supplied.

Guided practice

Predict concat("Left:"," seats")and explain the space.

Work with a partner. Make a prediction, compare your reasoning, then identify the rule that supports your answer.

Independent transfer

A code “007” is converted to a number and then displayed. What information may be lost?

Exit check

Why must the order of concatenation be preserved?

Write your reasoning before comparing with a classmate. If your teacher assigned this task, submit it through My classes to save your work and receive feedback.

Check yourself

  1. Question 1 of 2What is concat("A","B")under exact joining?

    Select one answer.

  2. Question 2 of 2Which TWO are text-representation concerns?

    Select exactly two answers (0 of 2 selected).

Your practice so far

Check an answer to see its rationale.

Teacher guidance and scoring