The intersection of two lines / sets

As with python, I'm looking for something that is equivalent to this python code ( sets ) in delphi5:

>>> 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']) 
+4
source share
1 answer
 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, ie, c = [3, 4] 

But be careful:

 var a, b, c: set of integer; 

not even compiled; instead, you get the value "Sets may have an error of no more than 256 elements." Further information on Delphi can be found in the documentation .

Update

Sorry, forgot to mention the "obvious" (from the point of view of the Delphi programmer):

 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, ie, c = ['C', 'D'] 

But your characters will be byte characters - that is, forget about Unicode (Delphi 5 does not support Unicode, so this is not a limitation in this case)!

+8
source

Source: https://habr.com/ru/post/1441362/


All Articles