Dan*_*ean 4 delphi intersection set char delphi-5
来自python我在delphi5中寻找与此python代码(sets)相当的东西:
>>> x = set("Hello")
>>> x
set(['H', 'e', 'l', 'o'])
>>> y = set("Hallo")
>>> y
set(['a', 'H', 'l', 'o'])
>>> x.intersection(y)
set(['H', 'l', 'o'])
Run Code Online (Sandbox Code Playgroud)
var
a, b, c: set of byte;
begin
a := [1, 2, 3, 4];
b := [3, 4, 5, 6];
c := a*b; // c is the intersection of a and b, i.e., c = [3, 4]
Run Code Online (Sandbox Code Playgroud)
但要注意:
var
a, b, c: set of integer;
Run Code Online (Sandbox Code Playgroud)
甚至不会编译; 相反,你得到'集合最多可能包含256个元素'错误.有关Delphi集的更多信息,请参阅文档.
更新
对不起,忘了提到'明显'(从Delphi程序员的角度来看):
var
a, b, c: set of char;
begin
a := ['A', 'B', 'C', 'D'];
b := ['C', 'D', 'E', 'F'];
c := a*b; // c is the intersection of a and b, i.e., c = ['C', 'D']
Run Code Online (Sandbox Code Playgroud)
但是你的字符都是字节字符 - 也就是说,忘记了Unicode(Delphi 5不支持Unicode,所以在这种情况下这不是真正的限制)!