Author: Ido Kanner
How can i change my 12345 numbers to hebrew numbering style ?
Answer:
Well I have created long ago in the pascal days a function to do this. A few month
ago i converted it to Delphi, and created a new function to do it. It's much faster
then the old one... but still it is to slow (I hope you can help me to make it even
faster).
Note: this is a recorsive function, and also this is the first time i published it,
I took it from my String unit, so it might be that there are some functions that
apper only in this unit, so I'm sorry from a head :) :
1 { Hebrew Numbers }
2 const
3 hZerrowToNine: array[0..9] of char =
4 // 0 1 2 3 4 5 6 7 8 9
5 (#255, '?', '?', '?', '?', 'ä', 'å', '¿', '?', '?');
6 //No Zerro in hebrew !!!!
7
8 hTenToNinte: array[1..9] of char =
9 // 10 20 30 40 50 60 70 80 90
10 ('é', '?', '?', '?', '?', '?', '?', '?', 'ö');
11
12 hHandredToFour: array[1..4] of char =
13 //100 200 300 400
14 ('÷', '¸', '?', '?');
15
16 ///////// Inner function for the "hIntToStrNumber" function \\\\\\\\\
17
18 function Single(strNum: string): string;
19 begin
20 result := hZerrowToNineNumbers[strToInt(strNum)];
21 end;
function Tens(strNum: string): string;
begin
case strNum[1] of
'1': if strNum[2] = '0' then
result := hTenToNinteNumbers[strToInt(strNum[1])]
else
result := hZerrowToNineNumbers[StrToInt(strNum[2])] + #32 + hTeen;
'2'..'9': result := hTenToNinteNumbers[strToInt(strNum[1])];
else
result := #255;
end;
end;
function Hundreds(strNum: string): string;
begin
case strNum[1] of
'1', '2': result := hHanderndToNineHandrend[StrToInt(strNum[1])];
'3'..'9': result := hZerrowToNineNumbers[strToInt(strNum[1])] + #32 +
hHundrends;
else
result := #255;
end;
end;
function Thousand(strNum: string): string;
begin
case strNum[1] of
'1', '2': result := hOneThousandToNineThousand[strToInt(strNum[1])];
'3'..'9': result := hZerrowToNineNumbers[strToInt(strNum[1])] + #32 + hThousand;
else
result := #255;
end;
end;
/////////////////////////////////////////////////////////////////////
function hIntToStrNumber(Number: integer): string;
//Thanks for HU-Man for helping to fix a bug that was in this function ...
var
strNum: string;
begin
strNum := IntToStr(Number);
case Length(strNum) of
1:
begin // 0 - 9
result := Single(strNum);
end;
2:
begin // 10 - 99
result := Tens(strNum);
if strNum[1] >= '2' then
if strNum[2] <> '0' then
result := result + #32 + hAnd + hIntToStrNumber(StrToInt(strNum[2]));
end;
3:
begin // 100 - 999
result := Hundreds(strNum);
if strNum[2] <> '0' then
if strNum[3] = '0' then
result := result + #32 + hAnd + hIntToStrNumber(StrToInt(strNum[2] +
strNum[3]))
else
result := result + #32 + hIntToStrNumber(StrToInt(strNum[2] +
strNum[3]));
if (strNum[2] = '0') and (strNum[3] <> '0') then
result := result + #32 + hAnd + hIntToStrNumber(StrToInt(strNum[3]));
end;
4:
begin // 1,000 - 9,999
result := Thousand(strNum);
if (strNum[2] <> '0') then
result := result + #32 + hIntToStrNumber(StrToInt(strNum[2] + strNum[3] +
strNum[4]));
end;
else
result := '';
end;
result := DeleteChar(Result, #255);
end;
|