Strings

What is a string?

  • A string is a collection of charecters. What is a charector as charector can be anything from numbers, letters, spaces, special symbols, etc.
  • Certain procedures may be used with strings and they vary from progaramming language to language Python examples
  • len() to find the length of a string
  • lower() to converte to lowercase
  • etc. Psuedocode examples
  • len() returns the lengh of a string
  • concat() returns a string made up of the concatenated strings ex. concat("string1", "string2") would return string1string2
  • substring() returns the charectors from the string beginning at the at the first position to the last so an example of this would be substring("abcdefghijk", 2, 5) would print bcde (puesdocode starts at 1)
  • Note: selections are conditional statements in collegeboard

String Concatenation

What is string concatenation?

  • String concatenation is combining 2 or more strings to make a new strings in order to create a new string
  • concat() in pusedocode and varys from language to language can be used to combine to strings such as concat("cookie","monster") returns cookiemonster

Substings

What is a substring?

  • A substring is a part of and already existing string.
  • In psuedocode substring() method is used for instance for concat("Mr.Mortenson is very handsome" 1, 2) the system would return Mr (remember that pusedocode starts at 1)

Hacks

  • Complete the following examples by writing down the result. Then using python convert the psuedocode into working code.

Example 1

Noun = "Mr.Mortenson" Adjective = "handsome" Adjective2 = "Very" Verb = "is" abrev = subtring(Noun, 1, 7) yoda = concat(Adjective2, " ", Adjective, " ", abrev, " ",Verb, ".") DISPLAY {yoda}

Example 2

cookie = "choclate" cookie2 = "rasin" len1 = "cookie/2" len2 = "cookie2*45" vote1 = ("cookie", "vote", "len2") vote2 = ("cookie2", "vote", "len1") votes = (concat(vote1, " ", vote2)) display {votes}

Disclaimer

Work in progress more hack problems for practice will be available on presentation day