Vetor de carateres de uma string

Delphi

27/04/2005

Como criar um vetor com cada letra de uma string?

DELPHI

vet[1]=´D´
vet[2]=´E´
vet[3]=´L´
vet[4]=´P´
vet[5]=´H´
vet[6]=´I´

Obrigado.


Fernando Lempê

Fernando Lempê

Curtidas 0

Respostas

Beppe

Beppe

27/04/2005

// se vetor é dinâmico
SetLength(V, Length(S));

// este código funciona tanto com dinâmico como estático
for I := 1 to Length(S) do
V[I + Low(V) - 1] := S[I];

// ou ainda
Move(Pointer(S)^, V[Low(V)], Length(S));

PS: Não testei. Se for estático assegure-se da largura do array.


GOSTEI 0
Yallebr

Yallebr

27/04/2005

DELPHI

vet[1]=´D´
vet[2]=´E´
vet[3]=´L´
vet[4]=´P´
vet[5]=´H´
vet[6]=´I´

var
  Vet : string of array
  Cont: SmallInt

SetLenght(Vet,Lenght(SuaString))
For Cont := 1 to Lenght(SuaString) do
  Vet[Cont] := SuaString[Cont]



GOSTEI 0
POSTAR