CharacterTypes (Delphi)
Contents
Description
The following example demostrates the use of some routines in Character unit that allow to determine the type of a character. When the user types something in the first memo, the second one gets filled with relevant information.
Code
procedure TMainForm.mmTextChange(Sender: TObject);
var
AllText: String;
I: Integer;
LDigits, LLetters, LNumber,
LLower, LUpper, LPuct,
LSep, LSymbols, LWhites: Integer;
begin
{ Calculate all all kinds of charcters in the memo }
AllText := mmText.Text;
LDigits := 0;
LLetters := 0;
LLower := 0;
LUpper := 0;
LNumber := 0;
LPuct := 0;
LSep := 0;
LSymbols := 0;
LWhites := 0;
for I := 1 to Length(AllText) do
begin
{ Check for digit }
if IsDigit(AllText[I]) then Inc(LDigits);
{ Check for number }
if IsNumber(AllText[I]) then Inc(LNumber);
{ Check for letter }
if IsLetter(AllText[I]) then Inc(LLetters);
{ Check for lower-cased letter }
if IsLower(AllText[I]) then Inc(LLower);
{ Check for upper-cased letter }
if IsUpper(AllText[I]) then Inc(LUpper);
{ Check for punctuation }
if IsPunctuation(AllText[I]) then Inc(LPuct);
{ Check for separators }
if IsSeparator(AllText[I]) then Inc(LSep);
{ Check for symbols }
if IsSymbol(AllText[I]) then Inc(LSymbols);
{ Check for symbols }
if IsWhiteSpace(AllText[I]) then Inc(LWhites);
end;
mmRes.Text := Format('%d digits; %d numbers; %d letters; ' +
'(%d upper and %d lower); %d puctuation; %d separators; ' +
'%d symbols; %d whitespaces',
[LDigits, LNumber, LLetters, LLower, LUpper, LPuct,
LSep, LSymbols, LWhites]
);
end;
Uses
- System.Character.IsDigit ( fr | de | ja )
- System.Character.IsNumber ( fr | de | ja )
- System.Character.IsLetter ( fr | de | ja )
- System.Character.IsLower ( fr | de | ja )
- System.Character.IsUpper ( fr | de | ja )
- System.Character.IsPunctuation ( fr | de | ja )
- System.Character.IsSeparator ( fr | de | ja )
- System.Character.IsSymbol ( fr | de | ja )
- System.Character.IsWhiteSpace ( fr | de | ja )