delhpi 字符比较的问题

来源:百度知道 编辑:UC知道 时间:2024/06/05 07:46:21
设置变量
tmpstr : string;
如下语句:如果tmpstr不等于'10','11','12'那么
如果tmpstr是char的话,可以写成
if not (tmpstr in ['10','11','12']) then
可是string怎么写?

delphi的字符串不能用in,也不能用case xx of。
要么老老实实地写:
if tmpstr<>'10' and tmpstr<>'11' and tmpstr<>'12' then
begin
end;

要么,
const ss:array[1..3] of string=('10','11','11');
var iCount:integer;
var exists:boolean;

exists:=false;
for iCount:=low(ss) to high(ss) do
begin
if tmpstr=ss[iCount] then
begin
exists:=true;
break;
end;
end;

if not exists then
begin
end;