Fórum comparando strings com operador in #333284
17/11/2006
0
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´
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
Curtir tópico
+ 0
Responder
Posts
18/11/2006
Marcio.theis
Você pode fazer da seguinte forma:
Somente declare [b:91847eab9b]StrUtils[/b:91847eab9b] no uses...
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...
Responder
Gostei + 0
20/11/2006
Carlos_tedex
Você pode fazer da seguinte forma:
Somente declare [b:d91b33560d]StrUtils[/b:d91b33560d] no uses...
case AnsiIndexStr(Str,[´casa´,´loja´,´teste´]) of 0 : // Str = ´casa´ 1 : // Str = ´loja´ 2 : // Str = ´teste´ -1 : //Nenhuma das strings end;
Valew Marcio, essa dica foi muito boa, resolveu meu problema...
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)