Custom format?

dannidanni Denmark
edited 11:34PM in FastReport .NET
Hello,

When I try to make a custom format on a string nothing happens?

I have a string "xxxxxxxxxx" I want to change to "xxxxxx-xxxx". I right click on the reportobject and press format. Then Custom format.

Comments

  • edited 11:34PM
    Hello,

    Custom format uses String.Format() function to format a value. It cannot format string-type value.
    You may use custom function to return a formatted value. Add the following code to the report script:
        private string FormatMask(string value, string mask)
        {
          MaskedTextProvider pro = new MaskedTextProvider(mask);
          pro.Add(value);
          return pro.ToString();
        }
    

    Use in the Text object:
    [FormatMask("1234567", "000-0000")]
  • edited 11:34PM
    AlexTZ wrote: »
    Hello,

    Custom format uses String.Format() function to format a value. It cannot format string-type value.
    You may use custom function to return a formatted value. Add the following code to the report script:
        private string FormatMask(string value, string mask)
        {
          MaskedTextProvider pro = new MaskedTextProvider(mask);
          pro.Add(value);
          return pro.ToString();
        }
    

    Use in the Text object:
    [FormatMask("1234567", "000-0000")]

    Can I pass a table field(Employees.FirstName) as the first parameter to the function FormatMask(value, mask) ?
  • edited 11:34PM
    Hello,

    Sure:
    [FormatMask([Employees.FirstName], "000-0000")]
  • edited 11:34PM
    AlexTZ wrote: »
    Hello,

    Sure:
    [FormatMask([Employees.FirstName], "000-0000")]

    Thanks !
    Your help is very useful.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.