TLDR
A string is an ordered sequence of characters, and in AP Computer Science Principles you mainly do two things with them: join strings together (concatenation) and pull out a piece of a string (a substring). The exam asks you to evaluate string expressions and predict their output, so focus on what each operation produces.

Why This Matters for the AP Computer Science Principles Exam
String questions on the multiple-choice section test whether you can determine the result of code that manipulates text. You trace an expression, figure out which characters are joined or extracted, and pick the exact output. Strings also show up naturally in the Create performance task whenever your program builds messages, labels, or user-facing text, so understanding concatenation and substrings helps you both read code and write it.
A key thing to remember: AP CSP does not require one specific programming language. The exam reference sheet uses a neutral pseudocode, and your class might use Python, JavaScript, blocks, or something else. The concepts of concatenation and substrings stay the same across all of them, even though the exact syntax and indexing rules can change.
Key Takeaways
- A string is an ordered sequence of characters that you can reference by index.
- String concatenation joins two or more strings end to end to make a new string.
- A substring is part of an existing string.
- The same concept can look different in different languages, so watch the syntax your code uses.
- Indexing rules (where counting starts, whether the end is included) depend on the language, so read carefully before predicting output.
- On the exam, your main job is to evaluate string expressions and determine the exact result.
What Strings Are
A string is an ordered sequence of characters, such as letters, digits, spaces, and symbols. Because the characters are ordered, you can reference them by index, similar to how you reference elements in a list.
You can't do arithmetic on strings the way you do with numbers, but you can still manipulate them. The two string operations you need for AP Computer Science Principles are concatenation and creating substrings.
Concatenation
String concatenation joins two or more strings end to end to make a new string. In many languages this is written with the + operator.
</>Codepart_one = "Hello" part_two = "_World!" print (part_one + part_two)
This outputs:
</>CodeHello_World!
The two strings are placed back to back in order, producing one combined string. Notice that nothing is added between them automatically, so the underscore and spaces you see come from the strings themselves.
Substrings and Slicing
A substring is a part of an existing string. For example, "APcomputer" is a substring of "APcomputerscienceprinciples". Pulling out a substring is often called slicing.
Here is one way to slice a string in Python:
</>Codestring_example1 = "APcomputerscienceprinciples" print (string_example1[0:10])
This prints the substring "APcomputer". In Python, index values start at 0, and the character at the ending index (10) is not included. So the slice grabs characters at indices 0 through 9.
Another example:
</>Codestring_example2 = "APcomputerscienceprinciples" print (string_example2[2:9])
This returns "compute".
Be careful here: Python uses zero-based indexing and excludes the end index, but other languages and the exam reference pseudocode may index differently. Always check how the language in the question counts before deciding what a slice returns.
How to Use This on the AP Computer Science Principles Exam
Determine the Result
Most string questions ask you to predict the exact output. Work left to right, applying each operation as you go.
- For concatenation, write out the strings side by side in order and include every space, underscore, or symbol exactly as shown.
- For a substring, identify the starting index, the ending index, and whether the end is included based on the language.
Code Tracing
When you trace string code:
- Note the original string and its character positions.
- Apply each slice or concatenation step and write down the intermediate result.
- Compare your final string to the answer choices character by character, including capitalization and spacing.
Create Performance Task
If your program displays text to the user, concatenation lets you build that text from smaller pieces, and substrings let you pull out parts of input or data. Being comfortable with these operations makes it easier to read your own code and explain how it works.
Common Trap
Off-by-one mistakes are the most common error. Double-check whether indexing starts at 0 or 1 and whether the ending index is included, since this changes which characters end up in your substring.
Common Misconceptions
- Concatenation does not add spaces for you.
"Hello" + "World"produces"HelloWorld", not"Hello World". Any space has to be part of one of the strings. - Indexing rules are not universal. Python starts at index 0, but other languages and the exam pseudocode may start at 1. Don't assume; check the question.
- A slice end index may not be included. In Python,
[0:10]stops at index 9. Treating the end index as included is a frequent source of wrong answers. - Strings are not numbers. Even if a string looks like
"42", you can't do arithmetic on it the way you do with the number 42 unless it is converted first. - Concatenation builds a new string. Joining strings creates a new combined string rather than changing the original strings in place.
Related AP Computer Science Principles Guides
Vocabulary
The following words are mentioned explicitly in the College Board Course and Exam Description for this topic.Term | Definition |
|---|---|
string concatenation | The operation of joining two or more strings end-to-end to create a new string. |
substring | A contiguous sequence of characters that forms part of an existing string. |
Frequently Asked Questions
What is a string in AP CSP?
A string is an ordered sequence of characters, such as letters, digits, spaces, or symbols. AP CSP uses strings when programs store or manipulate text.
What is string concatenation?
String concatenation joins two or more strings end to end to make a new string. Nothing is added automatically, so spaces or punctuation must be included in one of the strings.
What is a substring?
A substring is part of an existing string. For example, a substring operation can extract a few characters from the middle, beginning, or end of a larger text value.
Do AP CSP string indexing rules always start at 0?
No. AP CSP is language neutral, and indexing rules depend on the language or pseudocode in the question. Always check where indexing starts and whether the ending position is included.
How are strings tested on the AP CSP exam?
Strings are usually tested by asking you to evaluate expressions that concatenate strings or extract substrings. You need to predict the exact output, including spaces and capitalization.
Why do off-by-one errors happen with substrings?
Off-by-one errors happen when you include one too many or one too few characters, often because you misread the starting index or whether the ending index is included.