Советы по Delphi



Число строкой IX


Пришло от читателя письмо:

Посмотрел я что в разделе "Алгоритмы->Преобразование" много советов Число строкой, но нет преобразования на Украинский язык я подумал может модуль который я когда-то со славарем писал кому то спасет жизнь - так как у меня он уже года два работает.

unit UkrRecog;
{копирайт непомню чей. Был для русских циферок, а я переделал под
украинские}
{если кто что найдет пришлите
}{by Andrew Tkachenko, proektwo@netcity.ru, Ukraine,
}interface

Const

UkrMonthString : array[1..12] of string[9] = ('січня', 'лютого', 'березня', 'квiтня', 'травня','червня', 'липня', 'серпня', 'вересня', 'жовтня','листопада','грудня');
Function UkrRecognizeAmount(Amount:real;
CurrName,CurrSubname:string):string;

implementation
Uses
Sysutils;

Function UkrRecognizeAmount(Amount:real;
CurrName,CurrSubname:string):string;
{* CurrName in [грн.]
CurrSubName in [коп.]Распознается число <= 999 999 999 999.99*} const suffBL:string=' ';
suffDCT:string='дцять';suffNA:string='надцять ';suffDCM:string='десят';suffMZ:string='ь';sot:string='сот';st:string='ст';aa:string='а';ee:string='и'; {e}ii:string='і'; {и}oo:string='о';ov:string='ів';{ов}C2:string='дв';C3:string='тpи';C4:string='чотир';C5:string='п''ят';C6:string='шіст';C7:string='сім';C8:string='вісім';C9:string='дев''ят';var
i:byte;sAmount,sdInt,sdDec:string;IsMln,IsTha{,IsDcm},IsRange1019:boolean;currNum,endMlx,sResult:string;begin
if
(amount<=0)or(amount>999999999999.99) thenbeginResult:='<<<< Ошибка в диапазоне >>>>';Exit;end;STR(Amount:16:2,sAmount);sdInt:=Copy(sAmount,1,13);sdDec:=Copy(sAmount,15,2);IsMln:=false;//IsDcm:=false;IsTha:=false;IsRange1019:=false;sResult:='';
for i:=1 to 13 dobegincurrNum:=Copy(sdInt,i,1);
if currNum<>suffBL thenbegincase i of5,6, 7:if currNum<>'0' then IsMln:=true;8,9,10:if currNum<>'0' then IsTha:=true;end;

if i IN [2,5,8,11] then {сотни}beginif currNum='1' then sResult:=sResult+st+oo+suffBL;if currNum='2' then sResult:=sResult+C2+ii+st+ii+suffBL;if currNum='3' then sResult:=sResult+C3+st+aa+suffBL;if currNum='4' then sResult:=sResult+C4+ee+st+aa+suffBL;if currNum='5' then sResult:=sResult+C5+sot+suffBL;if currNum='6' then sResult:=sResult+C6+sot+suffBL;if currNum='7' then sResult:=sResult+C7+sot+suffBL;if currNum='8' then sResult:=sResult+C8+sot+suffBL;if currNum='9' then sResult:=sResult+C9+sot+suffBL;end;if i IN [3,6,9,12] then{десятки}beginif currNum='1' then IsRange1019:=true;if currNum='2' then sResult:=sResult+C2+aa+suffDCT+suffBL;if currNum='3' then sResult:=sResult+C3+suffDCT+suffBL;if currNum='4' then sResult:=sResult+'соpок ';if currNum='5' thensResult:=sResult+C5+suffMZ+suffDCM+suffBL;
if currNum='6' thensResult:=sResult+C6+suffMZ+suffDCM+suffBL;
if currNum='7' thensResult:=sResult+C7+suffMZ+suffDCM+suffBL;
if currNum='8' thensResult:=sResult+C8+suffMZ+suffDCM+suffBL;
if currNum='9' thensResult:=sResult+'дев''ян'+oo+st+oo+suffBL;
end;if i in [4,7,10,13] then {единицы}beginif (currNum='0') thenif IsRange1019 then sResult:=sResult+suffDCM+suffMZ+suffBL;if (currNum='1') thenbeginif (i=13)and(not IsRange1019) then sResult:=sResult+'одна ' else beginif (i=10)and(IsRange1019) then sResult:=sResult+'оди'elseif (i=10)and(not IsRange1019) then sResult:=sResult+'одна 'elsesResult:=sResult+'один'{ин};
if IsRange1019 and (i=13) thensResult:=sResult+'адцять'+suffBL
elseif IsRange1019 then sResult:=sResult+suffNAelse sResult:=sResult+suffBL;end;end;if (currNum='2') thenbeginsResult:=sResult+C2;if (i=10)and(IsRange1019=False) then sResult:=sResult+iielseif (i=10)or(IsRange1019) then sResult:=sResult+aaelse sResult:=sResult+{aa}ii;if IsRange1019 then sResult:=sResult+suffNAelse sResult:=sResult+suffBL;end;if (currNum='3') thenbeginsResult:=sResult+C3;if IsRange1019 then sResult:=sResult+suffNAelse sResult:=sResult+suffBL;end;if (currNum='4') thenbeginsResult:=sResult+C4;if IsRange1019 then sResult:=sResult+suffNAelse sResult:=sResult+ee+suffBL;end;if (currNum='5') thenbeginsResult:=sResult+C5;if IsRange1019 then sResult:=sResult+suffNAelse sResult:=sResult+suffMZ+suffBL;end;if (currNum='6') thenbeginsResult:=sResult+C6;if IsRange1019 then sResult:=sResult+suffNAelse sResult:=sResult+suffMZ+suffBL;end;if (currNum='7') thenbeginsResult:=sResult+C7;if IsRange1019 then sResult:=sResult+suffNAelse sResult:=sResult+suffBL;end;if (currNum='8') thenbeginsResult:=sResult+C8;if IsRange1019 then sResult:=sResult+suffNAelse sResult:=sResult+suffBL;end;if (currNum='9') thenbeginsResult:=sResult+C9;if IsRange1019 then sResult:=sResult+suffNAelse sResult:=sResult+suffMZ+suffBL;end;end;
endMlx:='';case i of4:beginif IsRange1019 then endMlx:=ov+suffBL elseif currNum='1' then endMlx:=suffBL elseif (currNum='2')or(currNum='3')or(currNum='4') thenendMlx:=aa+suffBL else endMlx:=ov+suffBL;sResult:=sResult+'мiльярд'+endMlx;end;7:if IsMln thenbeginif IsRange1019 then endMlx:=ov+suffBL elseif currNum='1' then endMlx:=suffBL elseif (currNum='2')or(currNum='3')or(currNum='4') thenendMlx:=aa+suffBL else endMlx:=ov+suffBL;sResult:=sResult+'мiльйон'+endMlx;end;10:if IsTha thenbeginif IsRange1019 then endMlx:=suffBL elseif currNum='1' then endMlx:=aa+suffBL elseif (currNum='2')or(currNum='3')or(currNum='4') thenendMlx:=ii+suffBL else endMlx:=suffBL;sResult:=sResult+'тисяч'+endMlx;end;end;{case}if i IN [4,7,10,13] then IsRange1019:=false;end;{IF}end;{FOR}
sResult:=sResult+CurrName+','+suffBL+sdDec+suffBL+CurrSubname ;sResult:=AnsiUpperCase(sResult[1])+Copy(sResult,2,length(sResult)-1);Result:=sResult;end;

end.

С уважением,

ООО "Проект ВО"
Украина, г.Харьков. [000857]




Содержание  Назад  Вперед