Board index » delphi » converting string characters to char characters

converting string characters to char characters

easy q:
want to convert single char string to a var of type char - see below. Is there
an easy way to do it? TIA.....

----------------------------------
var s,t:string;
     ch:char;

begin
s:='abcde';
t:=copy(s,1,1);
ch:=t; {doesn't compile with bp 7 or fpc !)
ch:=char(t); {typecaste- also doesn't compile with bp 7 or fpc....}
end.

John Lee, Logica UK, +44 (0)171 446 4357, l...@logica.com
-- opinions are mine--

 

Re:converting string characters to char characters


Quote
John Lee wrote:
> easy q:
> want to convert single char string to a var of type char - see below. Is there
> an easy way to do it? TIA.....

what about

var
  ch : char;
  s : string;
begin
  ch := s[1]
end.

Re:converting string characters to char characters


Quote
In article <78n5bi$...@romeo.logica.co.uk>, John Lee <l...@logica.com> wrote:
>easy q:
>want to convert single char string to a var of type char - see below. Is there
>an easy way to do it? TIA.....

>----------------------------------
>var s,t:string;
>     ch:char;

>begin
>s:='abcde';
>t:=copy(s,1,1);
>ch:=t; {doesn't compile with bp 7 or fpc !)
>ch:=char(t); {typecaste- also doesn't compile with bp 7 or fpc....}

ch:=t[1];

or just  ch:=s[1];

After all a string is an array of chars.  Make sure that the string is
not empty or unpredictable result will occur.

Osmo

Re:converting string characters to char characters


Quote
In article <78n5bi$...@romeo.logica.co.uk> l...@logica.com wrote...
> s:='abcde';
> t:=copy(s,1,1);
> ch:=t; {doesn't compile with bp 7 or fpc !)

  What about using ch := s[1]

Mike{*word*106}son, Black Cat Software Factory, Edinburgh, Scotland
fax 0131-271-1551 - Columnated Ruins Domino - Mellotron M400 #996

Other Threads