Return to Video

Selecting Substrings Solution - Programming Languages

  • 0:00 - 0:02
    Let's go through a possible answer together.
  • 0:02 - 0:04
    Here I've written out a candidate example.
  • 0:04 - 0:07
    Let's image that "bell hooks" is p and "curer bell" is q.
  • 0:07 - 0:11
    The first thing we're going to do is find the index into p of the first space.
  • 0:11 - 0:18
    Pindex space 0, 1, 2, 3, 4. This'll be 4 in our running example.
  • 0:18 - 0:25
    Qindex--the location of this space in q might be different--0, 1, 2, 3, 4, 5.
  • 0:25 - 0:27
    In fact in our example it is.
  • 0:27 - 0:30
    Now what I want to do is select out the first word in p.
  • 0:30 - 0:36
    I want everything from the beginning all the way up to, but not including, the space.
  • 0:36 - 0:40
    This selection goes to the left as far as it can but does not include pindex,
  • 0:40 - 0:42
    so it will be "bell."
  • 0:42 - 0:45
    I could also have put a 0 in here. That would have been exactly the same.
  • 0:45 - 0:48
    For q I don't want to start at position 5.
  • 0:48 - 0:53
    I actually want to start at position 6, starting with the b and going to the end of the word.
  • 0:53 - 0:56
    This is q's second word, which in our running example is also bell,
  • 0:56 - 0:59
    since bell equals bell, we'll just return True.
  • 0:59 - 1:05
    Curer Bell was actually a pseudonym, a false name, adopted by Charlotte Bronte, an author.
Title:
Selecting Substrings Solution - Programming Languages
Description:

more » « less
Video Language:
English
Team:
Udacity
Project:
CS262 - Programming Languages
Duration:
01:06

English subtitles

Revisions Compare revisions