You are familiar with this block:
Var
mySet: Set Of Char;
C: Char;
begin
mySet := ['a', 'b', 'c'];
If C In mySet Then ShowMessage('Exists');
end;
Is there any way to declare Set Of STRING
? or is there similar code that i can use instead? The important part of this block is If C In mySet Then ShowMessage('Exists');
I wanna use something like this about a set of string.
Thanks.
Sets are implemented using bit arrays. So no, you cannot have a 'set of string'. Use a TStringList instead, ie:
var
mySet: TStringList;
S: String;
begin
S := ...;
mySet := TStringList.Create;
try
mySet.Add('a');
mySet.Add('b');
mySet.Add('c');
if mySet.IndexOf(S) <> -1 Then ShowMessage('Exists');
finally
mySet.Free;
end;
end;
The RTL System.StrUtils
unit provides a very interesting method for this:
function MatchText(const AText: string; const AValues: array of string): Boolean; overload;
Use it like this:
if MatchText(sLanguages, ['fr-FR', 'en-GB', 'de-DE', 'it-IT', 'fr-CH', 'es-ES']) then
Writeln('found')
You can make use of this.
type
TAnyEnum = (aeVal1, aeVal2, aeVal3);
TEnuns = set of TAnyEnum;
TAnyMessages: array [TAnyEnum] of String;
const
MyMessages: TAnyMessages = ('Exists', 'Something else', 'WTF!?');
var
MySet : TEnums;
begin
MySet = [aeVal1, aeVal2];
If aeVal1 in MySet then ShowMessage(MyMessages[aeVal1]);
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With