Passing Chars to Strings.

Justin M. Mahoney (mahoneyjm98%cs25%us...@cadetmail.usafa.af.mil) wrote:
: Hi, I've been wondering how to do this simple task in Pascal lately:
: I want to make a string (teststring: string) equal to a character
: array (testchar: array [1..255] of char). I can't use the statement
: teststring := testchar because this is a type mismatch error.How do I
: go about passing the character array data into the string? Do I have
: to use pointers or some special type?

Easiest meathod:

{DOS}
uses Crt;
var
 aString: string;
 aArray: array[0..255] of char;
begin
  aString := 'Hello there';
  Move(aString[1], aArray, Length(aString));
  writeln(aString);
  writeln(aArray);

  repeat until keypressed;
end.

{Windows}
Uses WinCrt, Strings;
var
 aString: string;
 aArray: array[0..255] of char;
begin
  aString := 'Hello there';
  StrPCopy(aArray, aString);
  writeln(aString);
  writeln(aArray);
end.

Hope this helps
James :-)