TCharacterTypes (Delphi)
Description
The following example demostrates the use of some methods of TCharacter class 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 TCharacter.IsDigit(AllText[I]) then Inc(LDigits);
{ Check for number }
if TCharacter.IsNumber(AllText[I]) then Inc(LNumber);
{ Check for letter }
if TCharacter.IsLetter(AllText[I]) then Inc(LLetters);
{ Check for lower-cased letter }
if TCharacter.IsLower(AllText[I]) then Inc(LLower);
{ Check for upper-cased letter }
if TCharacter.IsUpper(AllText[I]) then Inc(LUpper);
{ Check for punctuation }
if TCharacter.IsPunctuation(AllText[I]) then Inc(LPuct);
{ Check for separators }
if TCharacter.IsSeparator(AllText[I]) then Inc(LSep);
{ Check for symbols }
if TCharacter.IsSymbol(AllText[I]) then Inc(LSymbols);
{ Check for symbols }
if TCharacter.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.TCharacter.IsDigit ( fr | de | ja )
- System.Character.TCharacter.IsNumber ( fr | de | ja )
- System.Character.TCharacter.IsLetter ( fr | de | ja )
- System.Character.TCharacter.IsLower ( fr | de | ja )
- System.Character.TCharacter.IsUpper ( fr | de | ja )
- System.Character.TCharacter.IsPunctuation ( fr | de | ja )
- System.Character.TCharacter.IsSeparator ( fr | de | ja )
- System.Character.TCharacter.IsSymbol ( fr | de | ja )
- System.Character.TCharacter.IsWhiteSpace ( fr | de | ja )