4.1.5

Strings

Test yourself

Strings

Strings are special cases of arrays or lists, where each element is a character. There are many methods we can apply to them:

Illustrative background for ConcatenationIllustrative background for Concatenation ?? "content

Concatenation

  • Concatenation is joining two strings together.
  • This can be done with the + sign. E.g:
    • "Hello " + "World" = "Hello World".
Illustrative background for Accessing a characterIllustrative background for Accessing a character ?? "content

Accessing a character

  • Remember, strings are just lists. So we can access a specific character in the exact same way as we access a list element:
    • string[3] would get the fourth character.
Illustrative background for Length of a stringIllustrative background for Length of a string ?? "content

Length of a string

  • The length of a string is given by the len function:
    • len("Hello") would give 5.
Illustrative background for SubstringsIllustrative background for Substrings ?? "content

Substrings

  • A substring is a part of a longer string.
  • In pseudocode, we use the function:
    • stringname.subString(startPos, numberOfChars)
  • This takes a substring starting at the 'startPos'th character, and takes the stated number of characters.

Jump to other topics

1Components of a Computer

2Software & Software Development

3Exchanging Data

4Data Types, Data Structures & Algorithms

5Legal, Moral, Cultural & Ethical Issues

6Elements of Computational Thinking

6.1Thinking Abstractly

6.2Thinking Ahead

6.3Thinking Procedurally

6.4Thinking Logically

6.5Thinking Concurrently

7Problem Solving & Programming

8Algorithms

Unlock your full potential with Seneca Premium

  • Unlimited access to 10,000+ open-ended exam questions

  • Mini-mock exams based on your study history

  • Unlock 800+ premium courses & e-books

Get started with Seneca Premium