string(1) to char?_(re)
Thu, 30 Nov 1995 11:12:36 -0500
Peter Gerwinski wrote:
>
> Hello, Thomas; hello, GPC-list!
>
> According to Thomas Dunbar:
> >
> > can one convert a string of length one into a char?
> >
> > ie the below wont work:
> >
> > program t(input,output);
> > var
> > ch:char;
> > s:string(10);
> > begin
> > s:='teststring';
> > writeln(substr(s,2,1));
> > ch:=substr(s,2,1);
> > writeln(ord(ch));
> > end.
>
> Yes, one can. The correct assignment reads
>
> ch:= s [ 2 ];
thanks, Peter.
i also find that readstr(substr(s,2,1),ch); works
but the packed array way is simpler.
thomas
>
> I think, this is Standard Pascal, nothing special. At least, it is
> common between UCSD, Borland and GNU Pascal.
>
> In the above sense, a string actually *is* a packed array of char.
>
> Yours,
>
> Peter
>
> --------------------------------------------------------------------------------
> Dipl. Phys. Peter Gerwinski
> Fachbereich Physik
> Universitaet-GH Essen Phone: +49-201-183-2763
> D-45117 Essen Fax: +49-201-183-2120
> Germany e-mail: pege@mail.theo-phys.uni-essen.de
> --------------------------------------------------------------------------------
--
Thomas Dunbar 540 231-3938 (fax 3714) http://gserver.grads.vt.edu/
Thomas Dunbar (tdunbar@gserver.grads.vt.edu)
HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada -
Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es