2005. november 1., kedd
How to check if all characters in a string are valid
Problem/Question/Abstract:
Is there a simple way of checking if all characters in a string are valid? For example valid chars are: "ABCabcd123". If the string I want to check contains "AA23c" it is valid, if it contains "AAY" it is invalid.
Answer:
This is one way to do it:
{ ... }
const
ValidChars = 'ABCabcd123';
type
EInvalidText = class(Exception);
var
iCount: Integer;
begin
for iCount := 1 to Length(Edit1.Text) do
if Pos(Edit1.Text[iCount], ValidChars) = 0 then
raise EInvalidText.Create('Invalid text entered.');
end;
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése