TURBO PASCAL

Новости

Программы   

Turbo Pascal 

Игры

Документация   

Странности

FAQ

Ссылки

Форум

Гостевая книга

Рассылка

Благодарности

Об авторе

 70: How do I convert an array of characters to a string? More
specifically, I haven't been able to convert an array of characters
into a string, so that I can write it to a file. The only way I have
been able to do it, is writing 1 char at a time.

 A: Carefully study these 
two simple test examples.  Note the
difference in the array's dimensions in the tests.
  type atype = array 
[0..20] of char;
  type stype = string[20];
  var s : stype;
      a : atype absolute s;
  begin
    FillChar (a, SizeOf(a), '*');
    s[0] := chr(20);
    writeln (s);
  end.
  type atype = array 
[1..20] of char;
  var s : string;
      a : atype;
  begin
    FillChar (a, Sizeof(a), '*');
    Move (a, s[1], 20);
    s[0] := chr(20);
    writeln (s);
  end.
Of course, you could 
also assign the array's characters one by one
to the string using a simple for loop (left as an exercise), but the
above methods are more efficient.

 Contents

На первую страницу

Rambler's Top100 Rambler's Top100
PROext: Top 1000

(с)Все права защищены

По всем интересующим вопросам прошу писать на электронный адрес

Hosted by uCoz