comparando strings com operador in

Delphi

17/11/2006

Gostaria de fazer comparações utilizando o operador ´in´ em Strings. Mas não estou conseguindo. Segue um exemplo do código:

begin
if ´teste´ in [´casa´,´loja´,´teste´] then
ShowMessage(´Existe´)
else
ShowMessage(´Não Existe´);
end;

Mensagem de Erro:
[Error] Unit1.pas(28): Ordinal type required
[Error] Unit1.pas(28): Incompatible types: ´Integer´ and ´String´
[Fatal Error] Project1.dpr(5): Could not compile used unit ´Unit1.pas´


Carlos_tedex

Carlos_tedex

Curtidas 0

Respostas

Marcio.theis

Marcio.theis

17/11/2006

Você pode fazer da seguinte forma:

case AnsiIndexStr(Str,[´casa´,´loja´,´teste´]) of
    0 : // Str = ´casa´
    1 : // Str = ´loja´
    2 : // Str = ´teste´
    -1 : //Nenhuma das strings
    end;


Somente declare [b:91847eab9b]StrUtils[/b:91847eab9b] no uses...


GOSTEI 0
Carlos_tedex

Carlos_tedex

17/11/2006

Você pode fazer da seguinte forma:
case AnsiIndexStr(Str,[´casa´,´loja´,´teste´]) of
    0 : // Str = ´casa´
    1 : // Str = ´loja´
    2 : // Str = ´teste´
    -1 : //Nenhuma das strings
    end;
Somente declare [b:d91b33560d]StrUtils[/b:d91b33560d] no uses...


Valew Marcio, essa dica foi muito boa, resolveu meu problema...


GOSTEI 0
POSTAR