【发布时间】:2016-02-23 20:16:29
【问题描述】:
我知道,我会写
if C in ['#', ';'] then ...
如果C 是AnsiChar。
但是这个
function CheckValid(C: Char; const Invalid: array of Char; OtherParams: TMyParams): Boolean;
begin
Result := C in Invalid; // <-- Error because Invalid is an array not a set
//maybe other tests...
//Result := Result and OtherTestsOn(OtherParams);
end;
产生E2015: Operator not applicable to this operand type。
有没有一种简单的方法可以检查字符是否包含在字符数组中(除了遍历数组)?
【问题讨论】:
-
['#', ':']是 char 集,而不是 char 数组,对于 Unicode 版本的 Delphi (2009+ ),请改用CharInSet,但请查看stackoverflow.com/questions/4237339/…中的注意事项 -
@GerryColl 你是对的,我相应地纠正了这个问题。谢谢你的提示。我的代码只是一个例子。但在这种特殊情况下,我担心
array of char。 -
您不能将
in运算符用于数组,只能用于集合。 -
澄清:
CheckValid()并不意味着尝试编写IsCharInArray()函数,而应仅作为用例的示例。
标签: delphi delphi-xe4