Funcao - filterchars |
Top Previous Next |
|
Como separar (filtrar) caracteres de uma string? { Abaixo da palavra implementation digite: }
type TChars = set of Char;
function FilterChars(const S: string; const ValidChars: TChars): string; var I: integer; begin Result := ''; for I := 1 to Length(S) do if S[I] in ValidChars then Result := Result + S[I]; end;
{ Para usar a função: - Coloque um botão no Form; - Altere o evento OnClick deste botão conforme abaixo: }
procedure TForm1.Button4Click(Sender: TObject); begin { Pega só letras } ShowMessage(FilterChars('D63an*%i+/e68l13', ['A'..'Z', 'a'..'z'])); { Pega só números } ShowMessage(FilterChars('D63an*%i+/e68l13', ['0'..'9']));
|