TLama

Untitled

Sep 8th, 2013
701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.80 KB | None | 0 0
  1. type
  2.   TCharSet = set of Char;
  3.  
  4. function IsStrValid(const Value: string; const Chars: TCharSet): Boolean;
  5. var
  6.   I: Integer;
  7. begin
  8.   Result := False;
  9.   for I := 1 to Length(Value) do
  10.     if not (Value[I] in Chars) then
  11.       Exit;
  12.   Result := True;
  13. end;
  14.  
  15. // or another version of the same could be...
  16. function IsStrValid(const Value: string; const Chars: TCharSet): Boolean;
  17. var
  18.   I: Integer;
  19. begin
  20.   Result := True;
  21.   for I := 1 to Length(Value) do
  22.     if not (Value[I] in Chars) then
  23.     begin
  24.       Result := False;
  25.       Exit;
  26.     end;
  27. end;
  28.  
  29. var
  30.   S: string;
  31. const
  32.   Allowed = ['A'..'Z', 'a'..'z', '0'..'9', '_'];
  33. begin
  34.   S := 'This_is_my_string_0123456789';
  35.   if IsStrValid(S, Allowed) then
  36.     ShowMessage('Ok')
  37.   else
  38.     ShowMessage('string contains invalid symbols');
  39. end;
Advertisement
Add Comment
Please, Sign In to add comment