Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type
- TCharSet = set of Char;
- function IsStrValid(const Value: string; const Chars: TCharSet): Boolean;
- var
- I: Integer;
- begin
- Result := False;
- for I := 1 to Length(Value) do
- if not (Value[I] in Chars) then
- Exit;
- Result := True;
- end;
- // or another version of the same could be...
- function IsStrValid(const Value: string; const Chars: TCharSet): Boolean;
- var
- I: Integer;
- begin
- Result := True;
- for I := 1 to Length(Value) do
- if not (Value[I] in Chars) then
- begin
- Result := False;
- Exit;
- end;
- end;
- var
- S: string;
- const
- Allowed = ['A'..'Z', 'a'..'z', '0'..'9', '_'];
- begin
- S := 'This_is_my_string_0123456789';
- if IsStrValid(S, Allowed) then
- ShowMessage('Ok')
- else
- ShowMessage('string contains invalid symbols');
- end;
Advertisement
Add Comment
Please, Sign In to add comment