Custom format?

dannidanni Denmark
edited 1:24AM 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 1:24AM
    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 1:24AM
    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 1:24AM
    Hello,

    Sure:
    [FormatMask([Employees.FirstName], "000-0000")]
  • edited 1:24AM
    AlexTZ wrote: »
    Hello,

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

    Thanks !
    Your help is very useful.

Leave a Comment