CSE 111, Fall 2000

Great Ideas in Computer Science

Lecture Notes #21

PROGRAMMING IN PASCAL:
TEXT PROCESSING (continued)

(10.    Substrings (continued))

a)  Recall that

        substr(T,N,L)

    is a Pascal function that outputs
    the substring of T
    that begins at position N
    and that has length = L.

b)    Click here for an example of a program
        that uses "substr".

        As you know from lecture, the output of this
        program is:

            Amherst, N.Y.

        Be sure you understand how this program
        works.

        To check your understanding, modify the
        program so that the output will be:

            Boston, Mass.
 
c)    Click here for another example of a program
        that uses "substr".

      As you know from lecture, this program
      takes as input a string and an integer,
      it splits the string into 2 parts, and then
      it switches those 2 parts, outputting the
      result.

        So, e.g., if the input is:

            'Buffalo Bills'
            5

        then the output is:

            'lo BillsBuffa'

d)    Suppose that S := 'Computer'.
        For each of the following,
            (i)    What do they compute?
           (ii)    Can you describe what they do in a
                    general way?

    a-    substr(S, 1, 1)
    b-    substr(S, 2, 1)
    c-    substr(S, 1, length(S))
    d-    substr(S, 1, length(S)-1)
    e-    substr(S, 2, length(S)-1)
    f-    substr(S, 2, length(S)-2)

    Click here for answers :-)


Copyright © 2000 by William J. Rapaport (rapaport@cse.buffalo.edu)

file: 111F00/lecturenotes21.30oc00.html