--> how to Alphabetical Index calculates Letter | Delphi Tips Trick

For Newbie

Tuesday, 15 November 2011

how to Alphabetical Index calculates Letter

| Tuesday, 15 November 2011


Function to facilitate the count value of the n-th letter of the alphabet. Let (n-th value of the letter 'c' is 3) with no manual counting (pake finger or imagined).

Function declaration:
type
   xChr = String [1]; / / Type Char false
IndexAbjad function (val: xChr): Byte;
const
   c: array [1 .. 26] of xChr = ('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j ',' k ',' l ',' m ',
                              'n', 'o', 'p', 'q', 'r', 's',' t ',' u ',' v ',' w ',' x ',' y ',' z ');
var
   i: Byte;
begin
   Result: = 0;
   / / Looping through characters that look similar to characters in the array
   for i: = 1 to High (c) do
   begin
     / / Use lowercase order => 'a' will be equal in value to 'A'
     Lowercase if (val) = c [i] then Result: = i;
   end;
end;

Examples of Implementation:
ShowMessage (IntToStr (indexAbjad ('h')));

Example # 2:
procedure TForm1.Button1Click (Sender: TObject);
begin
   Label2.Caption: = IntToStr (IndexAbjad (Edit1.Text));
end;

Related Posts

No comments: