7 Strings

 
A cow in a boat Description automatically generated with low confidence

This chapter covers

  • Representing strings as sequences of characters.
  • Solving problems with collections of characters.
  • Using and solving problems deploying strings as labels.
  • Evaluating the costs and benefits of string functions.
  • Using lexicographic order on strings.

Although humans communicate with words, computers use numbers. To allow computers to handle words, we represent words in code as strings. And just like words are composed of letters, strings are composed of characters. This chapter deals with strings and characters, and covers their use on the Bronze level.

You may be wondering why we use the terms “strings” and “characters” in computer programming, rather than “words” and “letters.” The reason is that "strings” and “characters” are broader terms. In English, letters are all the symbols A through Z, both lowercase and uppercase. Characters, however, include all those letters plus many other symbols, such as question marks, exclamation points, and even blank spaces between words. Likewise, in English, words are combinations of letters, like “hello.” Strings, however, are combinations of characters, many of which are definitely not words, such as “Lleho,” “lehlo,” “HhhhHHHello,” or even “?!.;:.”

7.1 Strings as Sequences of Characters

7.1.1 Representing Characters

7.1.2 Problems with Characters

7.2 Labels

7.3 Strings as Objects

7.3.1 Strings Algorithms

7.3.2 Lexicographic order

7.4 Summary

sitemap