In the following description, s1
and s2
may be
arbitrary string expressions, s
is a variable of string type.
WriteStr (s, write-parameter-list)
ReadStr (s1, read-parameter-list)
Text
files. The semantics is closely modeled after file I/O.
Index (s1, s2)
s2
is empty, return 1 else if s1
is empty return 0
else returns the position of s2
in s1
(an integer).
Length (s1)
s1
(an integer from 0 .. s1.Capacity
).
Trim (s1)
s
.
SubStr (s1, i)
SubStr (s1, i, j)
s1
that contains j
characters starting from i
. If j
is missing, return
all the characters starting from i
.
EQ (s1, s2)
NE (s1, s2)
LT (s1, s2)
LE (s1, s2)
GT (s1, s2)
GE (s1, s2)
s1
and s2
. Returns
a boolean result. Strings are not padded with spaces.
s1 = s2
s1 <> s2
s1 < s2
s1 <= s2
s1 > s2
s1 >= s2
s1
and s2
. Returns a
boolean result. The shorter string is blank padded to length of the
longer one, but only in --extended-pascal mode.
GPC supports string catenation with the +
operator or the
Concat function. All string-types are compatible, so you may
catenate any chars, fixed length strings and variable length
strings.
program ConcatDemo (Input, Output); var Ch : Char; Str : String (100); Str2: String (50); FStr: packed array [1 .. 20] of Char; begin Ch := '$'; FStr := 'demo'; { padded with blanks } Write ('Give me some chars to play with: '); ReadLn (Str); Str := '^' + 'prefix:' + Str + ':suffix:' + FStr + Ch; WriteLn (Concat ('Le', 'ng', 'th'), ' = ', Length (Str)); WriteLn (Str) end.
Note: The length of strings in GPC is limited only by the range of Integer (at least 32 bits, i.e., 2 GB, on most platforms), or the available memory, whichever is smaller).
When trying to write programs portable to other EP compilers, it is however safe to assume a limit of about 32 KB. At least Prospero's Extended Pascal compiler limits strings to 32760 bytes. DEC Pascal limits strings to 65535 bytes.