TCharacterTypes (C++)
From RAD Studio Code Examples
Language:
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
void __fastcall TMainForm::mmTextChange(TObject *Sender) { String allText = mmText->Text; int LDigits = 0; int LLetters = 0; int LLower = 0; int LUpper = 0; int LNumber = 0; int LPuct = 0; int LSep = 0; int LSymbols = 0; int LWhites = 0; /* Calculate all all kinds of charcters in the memo */ for (int i = 1; i <= allText.Length(); ++i) { /* Check for digit */ if (TCharacter::IsDigit(allText[i])) LDigits++; /* Check for number */ if (TCharacter::IsNumber(allText[i])) LNumber++; /* Check for letter */ if (TCharacter::IsLetter(allText[i])) LLetters++; /* Check for lower-cased letter */ if (TCharacter::IsLower(allText[i])) LLower++; /* Check for upper-cased letter */ if (TCharacter::IsUpper(allText[i])) LUpper++; /* Check for punctuation */ if (TCharacter::IsPunctuation(allText[i])) LPuct++; /* Check for separators */ if (TCharacter::IsSeparator(allText[i])) LSep++; /* Check for symbols */ if (TCharacter::IsSymbol(allText[i])) LSymbols++; /* Check for symbols */ if (TCharacter::IsWhiteSpace(allText[i])) LWhites++; } mmRes->Text = Format(String("%d digits; %d numbers; %d letters; ") + "(%d upper and %d lower); %d puctuation; %d separators; " + "%d symbols; %d whitespaces", ARRAYOFCONST((LDigits, LNumber, LLetters, LLower, LUpper, LPuct, LSep, LSymbols, LWhites)) ); }
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 )