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)