Substring/Top and tail: Difference between revisions
Content added Content deleted
Puppydrum64 (talk | contribs) |
(→Pascal: expand) |
||
Line 1,454: | Line 1,454: | ||
=={{header|Pascal}}== |
=={{header|Pascal}}== |
||
See [[ |
''See also [[#Delphi|Delphi]]'' |
||
{{works with|Extended Pascal}} |
|||
<lang pascal>program topAndTail(output); |
|||
var |
|||
line: string(20); |
|||
begin |
|||
line := 'ABCDEF'; |
|||
if length(line) > 1 then |
|||
begin |
|||
{ string with first character removed } |
|||
writeLn(subStr(line, 2)); |
|||
{ index range expression: only possible for strings } |
|||
{ _not_ designated `bindable` [e.g. `bindable string(20)`] } |
|||
writeLn(line[2..length(line)]); |
|||
{ string with last character removed } |
|||
writeLn(subStr(line, 1, length(line) - 1)); |
|||
{ only legal with non-bindable strings: } |
|||
writeLn(line[1..length(line)-1]) |
|||
end; |
|||
{ string with both the first and last characters removed } |
|||
if length(line) > 2 then |
|||
begin |
|||
writeLn(subStr(line, 2, length(line) - 2)); |
|||
{ only for non-bindable strings: } |
|||
writeLn(line[2..length(line)-1]) |
|||
end |
|||
end.</lang>It is imperative that <tt>firstCharacterIndex + substringLength</tt> specified to <tt>subStr(source, firstCharacterIndex, substringLength)</tt> must be valid index in <tt>source</tt>. Therefore you need to perform checks beforehand. |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |