我想查询一个string的类型的数据是否十几个情况,是否有函数像char型的:
var s:string;
if s[1] in ['a','b','d','g','h','7','1'] then
我用了
if s in ['begin','else','while','do','end','end','if'] then
报错?
var s:string;
if s[1] in ['a','b','d','g','h','7','1'] then
我用了
if s in ['begin','else','while','do','end','end','if'] then
报错?
当然可以用in啦。字符串不能用in,自己写个这样的函数吧,用动态数组作为参数,应该不难的。
try
sl.Add('begin'); sl.Add('else'); ...
i := sl.IndexOf(s);
Result := i <> -1;
finally
sl.Free;
end;
//老大,这个肯定不行了,像楼上的那样:
试一试这个:
var
vStr : Strings;
begin
vStr := TStringList.Create....
if vStr.Indexof(s) <> -1 then
ShowMessage('OK,肯定在里边的');
end;