Archived - Pascal : STRING and CHAR concatenation

This article has been archived and is no longer updated by Apple.
To concatenate using STRING types and CHAR types and not get a type mismatch
error, use the routine below to create a STRING containing the CHARacters the
user wishes to add to the STRING, then use the Pascal CONCAT to put them
together. Make sure that if this is done within a PROCEDURE or FUNCTION, and
the STRING is passed as a parameter, that the (*$V-*) option is used as well as
declaring a TYPE to pass rather than STRING.

TYPE STR_TO_PASS = STRING;

PROCEDURE WHATEVER (ST : STR_TO_PASS);
BEGIN
END;

here's the concat stuff ...

PROGRAM CONCAT_CHAR;

CONST LEN = 4; { or whatever you want }

VAR TEST_STRING : STRING;
CH : CHAR;
I : INTEGER;

(*$R-*) { turn Range Checking off so you can }
{ alter individual cells of the string }
BEGIN
TEST_STRING[0] := CHR(LEN); { set length of string }
FOR I := 1 TO LEN DO
BEGIN
READ (CH);
TEST_STRING[I] := CH;
END;
WRITELN;
WRITELN (TEST_STRING);
END.

Last Modified: Feb 18, 2012
Print this page
  • Last Modified: Feb 18, 2012
  • Article: TA47080
  • Views:

    1361
  • Rating:
    • 100.0

    (1 Responses)