Caractere Por Caractere De uma String

Delphi

17/08/2009

Galera gostaria ler caractere por caractere de uma string e por em um array

ex: a := ´CELULAR´;

b[1] := C;
b[2] := E;
b[3] := L;
b[4] := U;
b[5] := L;
b[6] := A;
b[7] := R;

e possível?? abraço!


Ipeixoto

Ipeixoto

Curtidas 0

Respostas

Guinther

Guinther

17/08/2009

Uma string é um array de char, então é perfeitamente possível acessar cada posição pelo índice, para ler ou atribuir. Um exemplo:

procedure TForm1.Button1Click(Sender: TObject);
var
s: string;
i: integer;
begin
s := ´CELULAR´;
for i := 1 to length(s) do
ListBox1.Items.Add(s[i]);
end;

Att,

Guinther Pauli
Editor Geral Revista ClubeDelphi
http://guintherpauli.blospot.com
http://twitter.com/guintherpauli


GOSTEI 0
POSTAR