【问题标题】:Crystal Reports phone numer水晶报表电话号码
【发布时间】:2020-05-19 14:31:34
【问题描述】:

我正在处理水晶报表,需要格式化电话号码字段。我正在处理的数据有些混乱,有些数字格式正确

(111)111-1111

还有一些 1111111111

我正在尝试编写这个公式来删除括号并重新格式化字符串。这是我到目前为止所拥有的,不知道为什么这不起作用

StringVar phone = Replace({AssessorTrainingReport;1.Phone1},"(",""); 
phone := Replace({AssessorTrainingReport;1.Phone1},")","");
Picture (CStr (phone), "(xxx) xxx-xxxx");

【问题讨论】:

  • 预期输出是什么?您想将第一个字符串格式化为第二个还是其他方式?

标签: crystal-reports formatting


【解决方案1】:

第二次替换调用应该对第一次替换调用的字符串变量结果进行操作...

phone := Replace(phone,")","");

另外,你也需要删除- 吗?

【讨论】:

  • 我实际上也尝试过这样做,但没有任何结果。我最终在我拉入存储过程的字段上使用了 sql replace 并修复了它。 replace(replace(replace(cj.Phone1, '-', ''),'(',''),')','') as Phone
【解决方案2】:

// 试试这个,在这种情况下,它可以让你替换任何你需要的东西。

    StringVar phone:= {yourTable.field};
    phone:= Replace(phone,"(","*");
    mid(phone, 1);
    replace(mid(phone, 1),")", "* "); 

【讨论】:

    【解决方案3】:

    试试这个...

    右键单击电话号码字段,然后选择格式字段 从格式字段选择常用选项卡。在显示字符串下单击 X-2 框 然后写公式 -> PICTURE({YOURTABLE.FIELD), "(XXX) XXX-XXXX")

    希望这有帮助!

    【讨论】:

    • 没有必要大喊大叫。偶尔尝试使用小写。
    【解决方案4】:

    如果您的数字可能“被弄乱”,那么您可能需要考虑清理整个字符串(也适用于那些好奇如何在 CR 中完成此操作的人):

    local stringvar phonenum := {table.phone_field};
    local stringvar out := "";
    local numbervar i;
    for i:=1 to length(phonenum) do
      (
        if isnumeric(phonenum[i]) then //iterate over the characters in the string...
           out:=out + phonenum[i]; //...and toss out those which are non-numeric
      );
    
    if length(out)&lt&gt10 then "Handle the error condition" else picture(out,"(xxx) xxx-xxxx")

    【讨论】:

      【解决方案5】:

      创建一个自定义函数来“补充” Replace() 函数:

      // ----------------------------------------------------------------------
      // ReplaceEx()
      // Author:      Craig Buchanan
      // Purpose:     Support an array of find tokens
      // Parameters:  text - the string being searched
      //              find - an array of characters to be found
      //              replacement - value to substitute
      // ----------------------------------------------------------------------
      Function (Stringvar text, Stringvar Array find, Stringvar replacement)
      
          local numbervar i;
      
          For i:=1 To Ubound(find) do (
      
              text:=Replace(text, find[i], replacement)
      
          );
      
          text;
      

      在公式字段中使用自定义函数:

      // returns {612) 555-1212
      Picture(ReplaceEx("612-555-1212", ["(",")","-"], ""), "(xxx) xxx-xxxx")
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-12-15
        • 2010-10-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多