Delphi - 将数组与字符串进行比较

时间:2016-01-30 19:40:16

标签: arrays delphi

好吧,我从头开始重塑这个话题,让想要帮助我的人明白一切。

我将数字转换为来自http://delphi.about.com/od/objectpascalide/a/curr2words.htm的字母(例如100 = 100),但似乎算法有很多错误。

我一个接一个地修理它们,我遇到了一些我无法解决的问题:

基本上,如果你键入" 2 000 000"它会给你" 200万,千"而不是" 200万"只要。 如果我写" 2 000 000 000"它会给你"二十亿,百万,千"而不是" 20亿"仅

对于我编写数百万个案例的内容,我能够使用它来修复它:

function ArrayToString(const Data: array of string): string;
       var
       SL: TStringList;
       S: string;
begin
SL := TStringList.Create;
try
for S in Data do
  SL.Add(S);
  Result := SL.Text;
finally
  SL.Free;
end;
 end;
 begin

 if ((ArrayToString(splitted[I]) <> (' thousand' + AnsiString(#13#10))))   then
       LettreFinal :=LettreFinal + splitted[I];

使用上面的代码获取&#39;千&#39;从字符串中删除(对于Billions案例或数百万案例)但我也想删除&#39;亿&#39;使用与上面相同的代码,我尝试了这个:

  if ((ArrayToString(splitted[I]) <> (' thousand' + AnsiString(#13#10))) or (ArrayToString(splitted[I]) <> (' million' + AnsiString(#13#10))))  then
       LettreFinal :=LettreFinal + splitted[I];

使用上面的代码不会删除数千,也不会删除数百万,所以它基本上没用(Splitted基本上是由,分割的字符串。)

1 个答案:

答案 0 :(得分:1)

对原始NumberToWords单元进行以下修改。

  function DoHundreds(const NumStr: string): string;

添加标记的行

  begin
    Result := '';   // Add this ************
    sLocNum := NumStr;

并在

的主体中
function ConvertToWords(const Number: double; UseCurrency: Boolean): string;

添加标记的行

  for iCount := 0 to slValSections.Count - 1 do
    begin
      sSectionVal := '';
      sSectionVal := DoHundreds(slValSections[iCount]);
      if iCount > 0 then
        if sSectionVal <> '' then       // Add this condition **************
          Result := sSectionVal + Suffix[iCount] + Result
        else                            // and this *********
      else
        Result := sSectionVal
    end;
相关问题